object references in event handlers prevent GC
ericsoco | 2009/03/21 | 2:03 pma bug in flash player 9 i came across today while trying to get a swf to unload completely:
https://bugs.adobe.com/jira/browse/FP-1770
if you have a reference to Keyboard or Capabilities (or, probably, a number of other native Classes as well) in an event handler, it will loiter as a pair of Class and Object references when the enclosing swf is unloaded via Loader.unload().
for example:
private function onKeyDown (evt:KeyboardEvent) :void {
if (evt.keyCode == Keyboard.SPACE) { doStuff(); }
}
must be replaced with:
private function onKeyDown (evt:KeyboardEvent) :void {
if (evt.keyCode == 32) { doStuff(); }
}
what a pain.






what about Keyboard.SPACE inside doStuff ()?
makc | 2009/03/22 | 7:37 amwhat about Keyboard.SPACE inside doStuff ()?
haven't tested that, but i imagine it's fine. i
ericsoco | 2009/03/22 | 10:46 amhaven’t tested that, but i imagine it’s fine. i think the problem with using it inside the event handler has to do with the way event handlers are stored in EventDispatcher instance queues; for some reason, using something like Keyboard in there keeps the event handler from getting properly removed from the EventDispatcher queue. calls from the event handler are not stored inside the EventDispatcher queue, and should not be an issue.
just a guess.