2012-10-27 22 views
0

即使發佈後也不會調用Dealloc。這是我的初始化代碼。Cocos2d:dealloc不會在調用發佈後調用

@interface PPTileMap : CCTMXTiledMap 
{ 

} 
@end 

@implementation PPTileMap 

-(void)dealloc 
{ 
    printf("Dealloc called\n"); 
} 
@end 

//allocation 
PPTileMap *tileMap = [[PPTileMap alloc] initWithTMXFile:tilemapFile]; 

//release 
[tileMap release]; 
tileMap = nil; 

當我使用tiledMapWithTMXFile然後加載線程後will..but崩潰。 爲什麼dealloc不被上面的代碼調用?

回答

3

的唯一原因,dealoc不發送release的對象是別人保留後調用(到NSArray或NSDictionary中,通過你的對象之一保留,你已經在其上運行的動作等)。如果你不知道,什麼對象保留你的對象,重寫它的retain方法

- (id) retain 
{ 
    return [super retain]; 
} 

然後將斷點這個方法裏面。然後,每當某個東西想要保留對象時,就能看到調用堆棧。您也可以覆蓋release方法

+0

非常感謝這個技巧...它的工作。 – Guru

+1

不用客氣 – Morion

0

最後解決了這個問題。特別感謝Morion。 這裏我明確使用了removeFromParentAndCleanup,然後調用dealloc。

//release 

[tileMap removeFromParentAndCleanup:YES]; 
[tileMap release]; 
tileMap = nil; 
相關問題