Force Garbage Collection in AS3?

2019-01-07 18:17发布

Is it possible to programmatically force a full garbage collection run in ActionScript 3.0?

Let's say I've created a bunch of Display objects with eventListeners and some of the DO's have been removed, some of the eventListeners have been triggered and removed etc... Is there a way to force garbage collection to run and collect everything that is available to be collected?

8条回答
放荡不羁爱自由
2楼-- · 2019-01-07 19:12
try {
    new LocalConnection().connect('foo');
    new LocalConnection().connect('foo');
} catch (e:*){
    trace("Forcing Garbage Collection :"+e.toString());
}
查看更多
贼婆χ
3楼-- · 2019-01-07 19:13

As others said: do not try to GC manually, there are hacks but it's not safe.

You should try recycling objects when you can - you'll save a lot of memory.

This can be applied for instance to BitmapDatas (clear and reuse), particles (remove from display and reuse).

查看更多
登录 后发表回答