我在Xcode這個錯誤:爲什麼我有內存問題?
objc[8422]: FREED(id): message release sent to freed object=0x3b120c0
我用Google搜索,發現有關的記憶。但我不知道哪一行代碼出錯了,有什麼想法?在模擬器中啓動我的應用程序之後,它會提示第二個,除了上述錯誤外,沒有其他錯誤。
@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];
}
}
我可以在removeFromSuperview之前保留controller.view嗎? – Tattat 2010-04-02 15:24:53
應該不需要保留或釋放它 - 特別是如果您要用新分配的視圖替換它。 – dstnbrkr 2010-04-02 15:26:40