我的應用程序需要通知UI聲音播放已完成。爲了實現這個目標,將偵聽器附加到SoundChannel對象的SOUND_COMPLETE事件中。我應該刪除監聽器的SOUND_COMPLETE事件嗎?
事件處理完成後,我應該刪除我的SOUND_COMPLETE事件偵聽器嗎?
private function playbackCompleteHandler(event:Event):void {
// Notify UI that playback is done etc
channel.removeEventListener(Event.SOUND_COMPLETE, playbackCompleteHandler);
}
大家都說我們應該總是刪除事件偵聽器,以便GC可以正確收集對象(在這種情況下,'channel'對象)。但似乎Adobe沒有做到這一點的官方文檔中[1] [2]
[1] http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html [2] http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d21.html
http://gingerbinger.com/2010/07/actionscript-3-0-events-the-myth-of-useweakreference/ – csomakk