Memory Leak in AS3 Loader Class
Posted: October 22nd, 2007 | Author: Tiago Bilou | Filed under: Actionscript3 | 27 Comments »Today I came across a nasty memory leak in the Loader Class.
I was writting a simple screensaver class that loads external images from the hdd and displays them. Sounds simple? It is. The problem was that everytime I loaded an image, the system memory would go up. I started by checking my eventListeners. They where all weak referenced. I went through the code looking for places where I could be keeping a reference and hence preventing the GC to collect it, but I couldn't find any.
There is something keeping the GC from removing the old images from memory...
Everytime the Loader calls the load() method the image is read into memory and stays there. I tried calling the unload() method but that doesn't help.
Then, how can one remove the loaded image from memory? If you know please let me know...
The only workaround I came up with was gskinners unsupported method to force the GC
This works great, but I would like to know what's keeping the GC from removing the previous images from memory...
Let me know if you have an answer.
Example showing the memory leak