fljot / Gestouch

Gestouch: multitouch gesture recognition library for Flash (ActionScript) development.
MIT License
356 stars 84 forks source link

Memory Leak With TapGesture #55

Open Vontre opened 11 years ago

Vontre commented 11 years ago

We are experiencing a nasty memory leak from the TapGesture class within a Starling based project. Basically we have a Sprite class which contains a number of dynamically created Sprites, each one having a tap function. Within the creation function we set up tap event listeners like so:

var tap:TapGesture = new TapGesture(item); tap.addEventListener(GestureEvent.GESTURE_RECOGNIZED, onTap, false, 0, true);

Where item is the Sprite object we want to listen to for taps. Even though the event is specified as weakly referenced, adding this line will cause the item and it's parent to be held in memory forever. I've done rigorous testing to determine that this is happening and this is the exact cause using manually called garbage collection calls and the Flash Builder memory profiler. Commenting the addEventListener line causes the sprites to be released from memory like normal.

I did a bit of poking around in the gestouch source and it looks like this cooould be because of a reference to the callback function (onTap in this case) being maintained in a dictionary (Gesture.as line 239). I didn't really do a thorough inspection of the source but that seemed like an obvious place to start looking.

Any insight into this issue would be appreciated. Thank you!

keyle commented 9 years ago

A year and four month... can my PR be looked at? :+1: :)

fljot commented 9 years ago

@keyle sorry for uhm delay) but I've dropped that event listeners management, check out the develop branch. why – because storing method as key in Dictionary with weak keys doesn't work anyway – it becomes available for GC immediately http://blog.gskinner.com/archives/2006/07/as3_dictionary_.html http://stackoverflow.com/a/11847463

keyle commented 9 years ago

Thanks for the response!

Should this issue be closed?

fljot commented 9 years ago

Do you encounter any memory leaks now?