我正在运行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变低,使游戏越来越慢!