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

查看:13
本文介绍了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 FAQ:

我应该保留/释放什么?

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 并释放所有资源它正在使用然后调用 end 方法在最高级别的 API 上你是使用.例如,如果您正在使用SimpleAudioEngine 然后只需调用[SimpleAudioEngine 结束].

If you need to completely shut down CocosDenshion and free all resources it was using then call the end method on the highest level API you are using. For example if you are using SimpleAudioEngine then just call [SimpleAudioEngine end].

如果您使用 CDSoundSource 对象,您必须通过其中之一获得它们工厂方法,例如声音源文件.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天全站免登陆