Skip to content

Instantly share code, notes, and snippets.

/Test

Created June 17, 2012 22:22
Show Gist options
  • Select an option

  • Save anonymous/2945904 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/2945904 to your computer and use it in GitHub Desktop.
Memory Management Cant release :( Objective c
#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
#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