iDevGames Forums
replacing a CCSprite with another: memory leaks? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: replacing a CCSprite with another: memory leaks? (/thread-8711.html)



replacing a CCSprite with another: memory leaks? - sefiroths - Mar 10, 2011 09:04 AM

I have a HellpWorld template.
i have a CCNode with a variable:

Code:
CCSprite *a;//in header

with an init function
Code:
a=[CCSprite spriteWithFile:"a.png"];
added the CCNode as child in helloworld.m init

if i want to replace the image with another one using always a.
i have a method inside the CCNode that makes:
Code:
a=[CCSprite spriteWithFile:"b.png"];
but nothing happens...
Code:
[a release];
a=[CCSprite spriteWithFile:"b.png"];
make it crash...
so i've tryed:
Code:
[a setTexture: [[CCTexture2D alloc] initWithImage:[UIImage imageNamed: @"b.png"]];
and it works, but i think it will have memory leaks because i have used alloc. correct me if i'm wrong.

but i don't know how to release the texture before loading another.
and why:
Code:
a=[CCSprite spriteWithFile:"b.png"]
doesnt work?
thanks


RE: replacing a CCSprite with another: memory leaks? - skyhawk - Mar 10, 2011 03:03 PM

the CCTextureCache handles the management of releasing and allocating textures.


RE: replacing a CCSprite with another: memory leaks? - sefiroths - Mar 11, 2011 08:57 AM

thanks i'll try