什么是delloc函数用于它自己运行?

时间:2010-12-31 04:20:00

标签: cocos2d-iphone

- (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];
}

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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