Reputation: 22042
CCSprite *sprite;
sprite.texture = [[CCTextureCache sharedTextureCache] addImage: @"mySpriteImage.png"];
sprite.position = ccp(width/2.0f, height/2.0f);
[self addChild:sprite z:2 tag:kTagMySprite];
...
[sprite removeFromParentAndCleanup:YES];
Is there a memory leak in the code above? Is the OpenGL texture released, or does it need to be released from the cache?
Upvotes: 1
Views: 1362
Reputation: 22042
I got solution, One of these call removes texture from CCTextureCache
and that removes OpenGL texture (glGenTextures id) .
[[CCTextureCache sharedTextureCache] removeTexture:sprite3.texture];
OR
[[CCTextureCache sharedTextureCache] removeTextureForKey:@"ImageName.png"];
OR
[[CCTextureCache sharedTextureCache] removeTexture:[(CCSprite*)[self getChildByTag:kTagBackground] texture] ];
Upvotes: 1
Reputation: 64477
Most questions can be answered by using the right tool. In this case, stackoverflow is not the tool. Instruments is.
You can also approach this with Vulcan logic. This piece of code is being used by thousands of developers worldwide. The probability of this code causing a memory leak has to be considered infinitesimal for a software library that has existed for over 3 years.
Upvotes: 3