SimpleAudioEngine Cocos2d 内存泄漏
我正在运行 Instruments,它表明 SimpleAudioEngine 正在泄漏内存。附上截图。尽管屏幕截图只显示了一个实例,但内存泄漏是多次的。
另外,有时它指向以下实现(我的代码):
-(void) preloadGameSounds
{
// pre load the background sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"farm_background_sound.mp3"];
// pre load the game sounds
[[SimpleAudioEngine sharedEngine] preloadEffect:@"chickenlayingegg.mp3"];
// setup ding sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"ding.caf"];
// egg pop sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"baloonpop.wav"];
// preload applause sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"applause.mp3"];
// wrong answer sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"wrong_answer_sound.wav"];
}
更改场景时,我也会卸载使用以下实现来发出声音:
-(void) unloadSoundEffects
{
[[SimpleAudioEngine sharedEngine] unloadEffect:@"applause.mp3"];
//[[SimpleAudioEngine sharedEngine] unloadEffect:@"wrong_answer_sound.wav"];
[[SimpleAudioEngine sharedEngine] unloadEffect:@"ding.caf"];
[[SimpleAudioEngine sharedEngine] unloadEffect:@"chickenlayingegg.mp3"];
}
此内存泄漏导致游戏的 FPS 变低,并使游戏速度越来越慢!
I am running Instruments and it indicates that the SimpleAudioEngine is leaking memory. The screenshot is attached. The memory leak is multiple times although the screenshot only shows one instance.
Also, sometimes it points to the following implementation (my code):
-(void) preloadGameSounds
{
// pre load the background sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"farm_background_sound.mp3"];
// pre load the game sounds
[[SimpleAudioEngine sharedEngine] preloadEffect:@"chickenlayingegg.mp3"];
// setup ding sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"ding.caf"];
// egg pop sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"baloonpop.wav"];
// preload applause sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"applause.mp3"];
// wrong answer sound
[[SimpleAudioEngine sharedEngine] preloadEffect:@"wrong_answer_sound.wav"];
}
When changing the scenes I also unload the sound using the following implementation:
-(void) unloadSoundEffects
{
[[SimpleAudioEngine sharedEngine] unloadEffect:@"applause.mp3"];
//[[SimpleAudioEngine sharedEngine] unloadEffect:@"wrong_answer_sound.wav"];
[[SimpleAudioEngine sharedEngine] unloadEffect:@"ding.caf"];
[[SimpleAudioEngine sharedEngine] unloadEffect:@"chickenlayingegg.mp3"];
}
This memory leak is making the FPS of the game to go low and making game slower and slower!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 cocosdenshion 常见问题解答:
From the cocosdenshion FAQ:
您是否使用模拟器来运行泄漏工具?
我在模拟器中遇到相同的泄漏,但在设备上却没有。
尝试使用设备运行泄漏工具
are you using simulator to run the leak tools ?
i encounter the same leak in simulator but not on device.
try using device to run the leak tools