iphone - Your idiom to avoid "potential leak" warnings with "distant" releases? -


dealing animation of large images, can this: alloc memory each of large images...

nsarray *imagesforlargeanimation;  #define img(x) [[uiimage alloc] \   initwithcontentsoffile:[[nsbundle mainbundle] \     pathforresource:@x oftype:@"tif"]]  imagesforlargeanimation  = [[nsarray alloc] initwithobjects:                     img("01"), // (since allocing image, of course must release eventually.)                     img("02"),                     img("03"),                     ....                     img("42"),                     nil];  animationarea.animationimages = imagesforlargeanimation; //blah blah... 

later, once animation has been stopped , no longer being shown onscreen, clean memory you'd have this:

-(void) cleanupthememoryinthebiganimation  {  //blah blah..   // each of big images in array, release memory:  (uiimage *uu in imagesforlargeanimation)     [uu release];   // release array  [imagesforlargeanimation release];  imagesforlargeanimation = nil; 

now, works , efficiently, not leak nor overuse memory if repeatedly use different large animations.

the problem is, of course clang warning: "potential leak of object allocated on line 69", indeed scores of warnings, 1 each alloc.

what's best idiom avoid these warnings -- , make safer , tighter?

does know?

for example, if use autorelease, thus, in code example above you'd use autorelease in img define...

...in fact, when release nsarray (ie, [imagesforlargeanimation release] ) ... @ point autorelease objects in array? correct? or??

(or should using sort of newblah function put images in, or .. ??)

if knows correct approach here avoid "potential leak", thanks!!!

{ps reminder never use imagenamed:, it's hopeless: it's suitable small ui-usage-type images. never use imagenamed!}

you don't need keep images retained - nsarray you.

try :

#define img(x) [[[uiimage alloc] \   initwithcontentsoffile:[[nsbundle mainbundle] \     pathforresource:@x oftype:@"tif"]] autorelease] 

and don't need code :

// each of big images in array, release memory: //for (uiimage *uu in imagesforlargeanimation) //    [uu release]; 

fyi (1) :

were use imagenamed not warning because imagenamed returns autoreleased objects alloc/initwithcontentsoffile not :)


fyi (2) :

there method on nsarrays performs selector on objects :

[imagesforlargeanimation makeobjectsperformselector:@selector(release)]; 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -