objective c - Analyze error when autorelease called on object returned by class_createInstance -


i'm adding code provided partner ios project calls class_createinstance , calls autorelease before returning, this:

class functionclass = objc_getclass(functionname); nsobject* functionobject = class_createinstance(functionclass, 0); [[functionobject performselector:@selector(initwithdictionary:) withobject:msg] autorelease]; 

when running analyze in xcode 4.0.2, following warning on last line:

object sent -autorelease many times 

question 1: how object getting sent autorelease many times?
understanding of class_createinstance need release value returns.

question 2: if code correct, how can avoid warning analyze?
have pretty strict policy not check in analyze warnings.

this decidedly odd pattern and, thus, analyzer isn't aware of it. use of class_createinstance() extremely rare.

two possible solutions off top of head:

  1. use preprocessor markup tell analyzer that, yes, in fact, functionobject retained reference (i don't have markup handy -- you'll find in release notes or on llvm.org site or search system headers).

  2. don't use class_createinstance(). once have reference class, use +alloc. better yet, rewrite entire expression [[objc_getclass(functionname) alloc] initwithdictionary:msg] , done it.

you should file bug via http://bugreporter.apple.com as, though odd, static analyzer shouldn't barf on that.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -