Why do I have memory problems?
- by Tattat
I got this error from XCode:
objc[8422]: FREED(id): message release sent to freed object=0x3b120c0
I googled and find that is related to the memory. But I don't know which line of code I go wrong, any ideas? After I launch my app in simulator, it prompts a second, than, no other error except the error above.
@implementation MyAppDelegate
@synthesize window;
@synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    [self changeScene:[MainGameMenuScene class]];
}
- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}
- (void) changeScene: (Class) scene
{
    BOOL animateTransition = true;
    if(animateTransition){
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; //does nothing without this line.
    }
    if( viewController.view != nil ) {
        [viewController.view removeFromSuperview]; //remove view from window's subviews.
        [viewController.view release]; //release gamestate 
    }
    viewController.view = [[scene alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT) andManager:self];
        //now set our view as visible
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    if(animateTransition){
        [UIView commitAnimations];  
    }   
}