Cocos2d iphone delloc函数用于什么?它是否自行运行?

Cocos2d iphone delloc函数用于什么?它是否自行运行?,cocos2d-iphone,Cocos2d Iphone,我有这个功能,它是用来做什么的?它是自动调用自己,还是当我们切换到另一个页面时,我们必须在最后调用它 它似乎释放了分配的内存。不,根据您给出的注释代码判断,它不会自动运行。当对象的保留计数变为零时(在释放调用期间),Objective c运行时会调用它。您可以释放您在dealloc中拥有的对象。如果您不了解它,为什么您有这个功能?您所说的“当对象的保留计数为零时”是什么意思?或者如何使其为零您需要在此处阅读有关IOS内存管理的内容:它不是内置函数?它似乎不是内置函数,是的。 - (void) d

我有这个功能,它是用来做什么的?它是自动调用自己,还是当我们切换到另一个页面时,我们必须在最后调用它

它似乎释放了分配的内存。不,根据您给出的注释代码判断,它不会自动运行。

当对象的保留计数变为零时(在释放调用期间),Objective c运行时会调用它。您可以释放您在dealloc中拥有的对象。

如果您不了解它,为什么您有这个功能?您所说的“当对象的保留计数为零时”是什么意思?或者如何使其为零您需要在此处阅读有关IOS内存管理的内容:它不是内置函数?它似乎不是内置函数,是的。
- (void) dealloc
{
    // in case you have something to dealloc, do it in this method
    // in this particular example nothing needs to be released.
    // cocos2d will automatically release all the children (Label)
    [_targets release];
    [_projectiles release];
    [_nottargets release];
    [_helicopters release];
    [_Explosions release];
    [_GameChances release];

    _targets=nil;
    _projectiles = nil;
    _nottargets=nil;
    _helicopters=nil;
    _Explosions=nil;
    _GameChances=nil;

    [super dealloc];
}