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