-
-
Save anonymous/2945904 to your computer and use it in GitHub Desktop.
Memory Management Cant release :( Objective c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "SPSprite.h" | |
| @interface GameCharacter : SPSprite{ | |
| SPTextureAtlas *characterTextureAtlas; | |
| SPTexture *characterTexture; | |
| SPImage *gameCharacter; | |
| } | |
| @property(retain)SPTextureAtlas *characterTextureAtlas; | |
| @property(retain)SPTexture *characterTexture; | |
| @property(retain)SPImage *gameCharacter; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "GameCharacter.h" | |
| @implementation GameCharacter | |
| @synthesize characterTextureAtlas; | |
| @synthesize characterTexture; | |
| @synthesize gameCharacter; | |
| -(void)dealloc{ | |
| NSLog(@"Done"); | |
| [super dealloc]; | |
| } | |
| -(id)init{ | |
| self = [super init]; | |
| if(self != nil){ | |
| characterTextureAtlas = [[[SPTextureAtlas alloc] | |
| initWithContentsOfFile:@"characterAtlas.xml"] autorelease]; | |
| characterTexture = [characterTextureAtlas textureByName:@"basicCharacter_4"]; | |
| NSLog(@"%d",[characterTexture retainCount]); //--> result = 1 | |
| gameCharacter = [SPImage imageWithTexture:characterTexture]; | |
| NSLog(@"%d",[characterTexture retainCount]); //--> result = 2 | |
| [self addChild:gameCharacter]; | |
| //**************************************************************************************** | |
| //How to release it correctly now? I checked with leak tools and I get a leak on this | |
| // but Im only calling once alloc] init... if I release this i get an error Bad Access... | |
| // by the way how to do the implementation also correctly in the dealloc? | |
| } | |
| return self; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment