Cocos2d:调用release后不调用dealloc [英] Cocos2d : dealloc is not called after calling 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
");
}
@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,由您的对象之一保留,您已对其运行操作等).如果你不知道,什么对象保留了你的对象,覆盖它的 retain
方法为
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:调用release后不调用dealloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!