objective c - NSMutableDictionary - "Incorrect decrement of the reference count of an object..." -


i have property in header file as

@property (nonatomic,retain) nsmutabledictionary* e;

and in viewdidload: method allocated like

self.e = [[nsmutabledictionary alloc] initwithcontentsofurl:myurl];.

the xcode static analyser triggered, , says 'potential leak of object...' obviously. when release object ([self.e release] in dealloc) error persists, saying there "incorrect decrement of reference count", , object not owned caller (my viewcontroller).

the 'incorrect decrement...' error goes away when replace [self.e release] [e release]. former error potential leak still there. problem?

this statement:

self.e = [[nsmutabledictionary alloc] initwithcontentsofurl:myurl]; 

is over-retaining object. both alloc-init , property retain object.

in terms of ownership, own object returned alloc-init , sending retain message in property accessor claim ownership of again, results in object being over-retained.

you can use convenience constructor, returns object yo not own, , let property accessor claim ownership of it:

self.e = [nsmutabledictionary dictionarywithcontentsofurl:myurl]; 

or make use of autorelease:

self.e = [[[nsmutabledictionary alloc] initwithcontentsofurl:myurl] autorelease]; 

or use temporary variable:

nsmutabledictionary *tempdict = [[nsmutabledictionary alloc] initwithcontentsofurl:myurl]; self.e = tempdict; [tempdict release]; 

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 -