I am trying to understand why instruments is saying the indicated lines in the following code is causing dirty memory growth. I am getting this in my second heap shot (after the baseline) after returning to the baseline state. Can anyone point out my error?
CCSprite *baseSprite = NULL;
CCSprite *mainHandSprite = NULL;
CCSprite *offHandSprite = NULL;
CCSprite *helmetSprite = NULL;
CCSprite *torsoSprite = NULL;
CCSprite *gloveSprite = NULL;
CCSprite *bootSprite = NULL;
NSString* afile = [NSString stringWithFormat:@"%@%i.PNG", file, num];
baseSprite = [[CCSprite alloc]initWithFile:afile]; /* HEAP GROWTH */
baseSprite.anchorPoint = ccp(0,0);
int w = baseSprite.textureRect.size.width;
int h = baseSprite.textureRect.size.height;
mainHandSprite = [self mainHandSprite:file And:num];
helmetSprite = [self headSprite:file And:num];
torsoSprite = [self torsoSprite:file And:num];
offHandSprite = [self shieldSprite:file And:num];
gloveSprite = [self gloveSprite:file And:num];
bootSprite = [self bootSprite:file And:num];
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:w height:h]; /*HEAP GROWTH */
[rt begin];
[baseSprite visit];
if (torsoSprite)
[torsoSprite visit];
if (helmetSprite)
[helmetSprite visit];
if (offHandSprite)
[offHandSprite visit];
if (bootSprite)
[bootSprite visit];
if (gloveSprite)
[gloveSprite visit];
if (mainHandSprite)
[mainHandSprite visit];
[rt end];
CCTexture2D *aTex = rt.sprite.texture;
[aTex setAntiAliasTexParameters];
[baseSprite release];
baseSprite = NULL;
[mainHandSprite release];
mainHandSprite = NULL;
[torsoSprite release];
torsoSprite = NULL;
[helmetSprite release];
helmetSprite = NULL;
[offHandSprite release];
offHandSprite = NULL;
[gloveSprite release];
gloveSprite = NULL;
[bootSprite release];
bootSprite = NULL;
return aTex;
The message just states where the instance is created not where it is leaked.
The variable
baseSpriteis retained elsewhere without a balancing release.For
rteitherCCRenderTexturereturns an un-autoreleased object or the variable is retained elsewhere without a balancing release.If you need to see where retains, releases and autoreleases occur for an object use instruments:
Run in instruments, in Allocations set “Record reference counts” on on (you have to stop recording to set the option). Cause the problem code to run, stop recording, search for there ivar of interest, drill down and you will be able to see where all retains, releases and autoreleases occurred.