SimpleAudioEngine Cocos2d内存泄漏 [英] SimpleAudioEngine Cocos2d Leaking Memory

查看:195
本文介绍了SimpleAudioEngine Cocos2d内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Instruments,它表明SimpleAudioEngine正在泄漏内存。附加了屏幕截图。内存泄漏是多次的,虽然截图只显示一个实例。

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

这种内存泄漏使游戏的FPS变低,慢和慢!

This memory leak is making the FPS of the game to go low and making game slower and slower!

推荐答案

cocosdenshion常见问题


我应该保留/ / strong>

What should I retain/release?

SimpleAudioEngine,CDAudioManager和
CDSoundEngine API都通过共享的单例实例访问

这是一个常见的模式,在Cocoa Touch和cocos2d中使用

共享实例不应该保留或释放

SimpleAudioEngine, CDAudioManager and CDSoundEngine APIs are all accessed through a shared singleton instance. This is a common pattern that is used throughout Cocoa Touch and cocos2d. The shared instance should not be retained or released.

如果需要完全关闭
CocosDenshion并释放所有资源
它使用然后调用结束方法
在最高级别的API你是
使用。 例如,如果您使用
SimpleAudioEngine,则只需调用
[SimpleAudioEngine end]

如果使用CDSoundSource对象,
必须通过
工厂方法之一获取它们,例如
soundSourceForFile。返回的CDSoundSource
是自动释放的,
意味着如果你想在
之外使用
必须保留的当前方法的作用域。如果你保留一个
CDSoundSource,你应该在完成使用后释放

If you use CDSoundSource objects you must obtain them through one of the factory methods such as soundSourceForFile. The CDSoundSource that is returned is autoreleased, that means if you want to use it outside the scope of the current method you must retain it. If you retain a CDSoundSource you should release it when you are finished using it.

这篇关于SimpleAudioEngine Cocos2d内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆