Force Garbage Collection in AS3?

前端 未结 8 2006
轻奢々
轻奢々 2020-11-30 07:33

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 a

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 08:38

    Yes, it's possible, but it is generally a bad idea. The GC should have a better idea of when is a good time to run than you should, and except for a very specific case, like you just used 500MB of memory and you need to get it back ASAP, you shouldn't call the GC yourself.

    In Flash 10, there is a System.gc() method you can call (but please don't, see above) - keep in mind System.gc() only works in the debugging version of Flash player 10+.

    In Flash 9, there is an unsupported way to force it via an odd LocalConnection command, but it may not work in all versions. See this post by Grant Skinner.

提交回复
热议问题