3

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. enter image description here

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!

Charles
  • 50,943
  • 13
  • 104
  • 142
azamsharp
  • 19,710
  • 36
  • 144
  • 222

2 Answers2

2

From the cocosdenshion FAQ:

What should I retain/release?

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.

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].

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.

Community
  • 1
  • 1
Michael Fredrickson
  • 36,839
  • 5
  • 92
  • 109
0

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

Lim Gim Hong
  • 306
  • 1
  • 3