【问题标题】:Cocos2d : dealloc is not called after calling releaseCocos2d:调用release后不调用dealloc
【发布时间】:2012-10-27 15:13:26
【问题描述】:

即使在释放之后也不会调用 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 时,它​​会..但在加载线程后崩溃。 为什么上面的代码不调用dealloc?

【问题讨论】:

    标签: cocos2d-iphone


    【解决方案1】:

    在发送release 后没有调用dealoc 的唯一原因是该对象被其他人保留(添加到NSArray 或NSDictionary,由您的一个对象保留,您已对其运行操作等) .如果你不知道,什么对象保留了你的对象,覆盖它的retain方法为

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

    然后在此方法中放置断点。然后,您将能够在每次想要保留您的对象时看到调用堆栈。你也可以覆盖release方法

    【讨论】:

      【解决方案2】:

      终于解决了这个问题。特别感谢 Morion。 这里我明确使用了 removeFromParentAndCleanup 然后调用了 dealloc。

      //release
      
      [tileMap removeFromParentAndCleanup:YES];
      [tileMap release];
      tileMap = nil;
      

      【讨论】:

        猜你喜欢
        • 2012-12-05
        • 2011-03-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-07
        • 1970-01-01
        • 1970-01-01
        • 2012-07-12
        相关资源
        最近更新 更多