开发者

How to trigger garbage collection?

开发者 https://www.devze.com 2023-04-11 15:39 出处:网络
Does anyone know if it\'s possible to apply garbage collection to the new StageVideo component in AS3?I have tried with no success!Code is below:

Does anyone know if it's possible to apply garbage collection to the new StageVideo component in AS3? I have tried with no success! Code is below:

if ( this._stageVideo == null )
{
    this._stageVideo = stage.stageVideos[0];
    this._stageVideo.addEventListener(StageVideoE开发者_运维技巧vent.RENDER_STATE, stageVideoStateChange);
}

Attempt at GC:

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


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

I'm surprised that it worked, it should throw an exception, you should first remove event listeners and then nullify it's reference.

Garbage collector does not start every time you nullify something, but if you can use Flash Builder profiler you can attempt to force GC, also if you want to test it out, you can package project as AIR, and call GC manually.

There is bug/feature that will invoke GC if you fail to start LocalConnection twice (http://www.nbilyk.com/flash-garbage-collection):

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号