我现在正在寻找内存泄漏在我的cocos2d-iphone 1.0.1游戏中使用泄漏工具。
到目前为止,我已经解决了几个问题。但有一件事被泄露了,我不太明白:
它是一个CCTimer对象。导致这次泄漏的线路是
// This method is called when you encounter a random battle.
-(void)transitionToBattle {
[self unschedule:@selector(transitionToBattle)];
// Displays a "loading" screen
[self schedule:@selector(battleLoading)interval:0.5];
// Enters actual battle scene
[self schedule:@selector(enterBattle) interval:0.8]; // <--- Leak here
}不确定是否相关,但enterBattle方法是
-(void)enterBattle {
[self unschedule:@selector(enterBattle)];
glColor4f(1, 1, 1, 1);
[[CCDirector sharedDirector]pushScene:[BattleScene scene]];
}battleLoading只是在屏幕上显示一个精灵:
-(void)battleLoading {
[self unschedule:@selector(battleLoading)];
// The scene itself is running a CCRotateBy action, so I'll stop it
[self stopAllActions];
// << Create CCSprite for "now loading" here >>
// It is possible for the scene to be rotated, so let's fix that
self.rotation = 0.0;
// Make sure that the rotation fix is noticed
[[CCDirector sharedDirector]drawScene];
}据我所知,cocos2d使用一个CCTimer来控制预定的选择器。然而,我不知道它怎么可能泄漏一个CCTimer。
这些方法所在的代码相当大,但我确信上面的代码段是唯一引用enterBattle的部分。
我可以注意到一旦你已经在战斗现场泄漏,所以它不会发生,当你退出它。泄漏并不总是发生,只是经常发生。
我看得出来,上面的细节不太准确,所以很难找出问题所在。因此,我想知道是否有一种合理的方法来调试泄漏的CCTimer,因为有日程安排。是什么导致了这一切?
它似乎只发生在这个特定的时间表上。我有很多其他的,而且似乎没有像这样泄露。
发布于 2013-12-27 01:21:04
似乎罪魁祸首是这样的:
[[CCDirector sharedDirector]drawScene];用我的battleLoading方法。
我真的不知道为什么。我刚把它移开,到目前为止我还没有再看到漏水的地方。
看看这个用于CCDirectorIOS的方法,它似乎做了一些与调度程序相关的事情。也许它对日程安排不太友好,特别是当你在改变场景或做什么的时候。
https://stackoverflow.com/questions/20600821
复制相似问题