Cocos2d:dealloc在调用release后不被调用 [英] Cocos2d : dealloc is not called after calling release

查看:139
本文介绍了Cocos2d:dealloc在调用release后不被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使发布后,Dealloc也不会被调用。这是我的初始化代码。

Dealloc is not called even after release. Here is my code for initialization.

@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?

When I use tiledMapWithTMXFile then it will..but crashes after loading thread. Why dealloc is not called for above code?

推荐答案

dealoc 发送 release 后,该对象被其他人保留(添加到NSArray或NSDictionary,由您的某个对象保留,您已经运行)动作等)。如果你不知道,什么对象保留你的对象,覆盖保留方法为

The only reason that dealoc is not called after sending release that the object is retained by someone else (added to NSArray or NSDictionary, retained by one of your objects, you have run action on it, etc.). If you don't know, what object retains your object, override it's retain method as

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

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

Then place breakpoint inside this method. Then you will be able to see the call stack every time something want to retain your object. You can also override release method

这篇关于Cocos2d:dealloc在调用release后不被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆