gpt4 book ai didi

cocos2d-iphone - SimpleAudioEngine Cocos2d 泄漏内存

转载 作者:行者123 更新时间:2023-12-01 14:59:19 25 4
gpt4 key购买 nike

我正在运行 Instruments,它表明 SimpleAudioEngine 正在泄漏内存。附上截图。尽管屏幕截图仅显示一个实例,但内存泄漏是多次的。 enter image description here

此外,有时它指向以下实现(我的代码):

-(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 变低并使游戏速度越来越慢!

最佳答案

来自cocosdenshion FAQ :

What should I retain/release?

SimpleAudioEngine, CDAudioManager andCDSoundEngine APIs are all accessedthrough a shared singleton instance.This is a common pattern that is usedthroughout Cocoa Touch and cocos2d.The shared instance should not beretained or released.

If you need to completely shut downCocosDenshion and free all resourcesit was using then call the end methodon the highest level API you areusing. For example if you are usingSimpleAudioEngine then just call[SimpleAudioEngine end].

If you use CDSoundSource objects youmust obtain them through one of thefactory methods such assoundSourceForFile. The CDSoundSourcethat is returned is autoreleased, thatmeans if you want to use it outsidethe scope of the current method youmust retain it. If you retain aCDSoundSource you should release itwhen you are finished using it.

关于cocos2d-iphone - SimpleAudioEngine Cocos2d 泄漏内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5235123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com