2011-10-07 56 views
0

有誰知道是否可以將垃圾回收應用到AS3中新的StageVideo組件?我嘗試過沒有成功!代碼如下:如何觸發垃圾收集?

if (this._stageVideo == null) 
{ 
    this._stageVideo = stage.stageVideos[0]; 
    this._stageVideo.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange); 
} 

嘗試在GC:

this._stageVideo = null; 
this._stageVideo.removeEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange); 
+0

有沒有這樣的事情「應用垃圾回收」,您只能通過刪除所有事件偵聽器和對象引用來準備要垃圾收集的對象。因此,如果您要顯示一些代碼,那就太好了 –

回答

1
this._stageVideo = null; 
this._stageVideo.removeEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange) 

我很驚訝,它的工作,它應該拋出一個異常,你應該先移除事件偵聽器,然後廢掉這是參考。

垃圾收集器在您每次取消某些操作時都不會啓動,但是如果您可以使用Flash Builder分析器,則可以嘗試強制GC,如果要測試它,也可以將項目打包爲AIR,然後手動調用GC 。

存在BUG /功能,如果你無法啓動的LocalConnection兩次(http://www.nbilyk.com/flash-garbage-collection)將調用GC:

try { 
    new LocalConnection().connect('foo'); 
    new LocalConnection().connect('foo'); 
} catch (e:Error) {} 
+0

是的,您的正確@nirth不應該工作,StageVideo對普通顯示對象的工作方式不同,所以這就是我感到困惑的地方!任何知道SV的人的任何建議? –

+0

好吧,我的壞,我很想參與垃圾收集StageVideo我錯過了刪除其他地方的事件監聽器! –