Just great
another weird Garbage Collector issue in AS3:
When I load an image using the Loader class and unload it later on. It won’t be disposed by the garbage collector.
There are no references to neither the Loader nor the (weak) eventlisteners. After loading the image a couple of times the memory goes sky high
.
Here is a (simple) example: loadertest.zip
Does anyone have an explaination on why the GC doesn’t clean the loaded content? I would be very grateful!
UPDATE 1 (2007-06-19):
I made the example even less complicated by using the same Loader instance when loading new images.
As I work around I tried to dispose the loaded BitmapData but unfortunately it had no effect.
I assume the leak is somewhere within the Loader (or even deeper in the code) and that the loaded (binary) data is not removed after it’s converted into a BitmapData.
UPDATE 2 (2007-06-19):
I found the solution on in this post:
http://www.webforumz.com/macromedia-flash/42690-memory-leak-when-loading-swf-in.htm
It seems that the unload() method has a bug when used in the flash IDE. Once I ran the test in a browser there seem to be no more problems and the GC nicely clears the memory…
Lets hope Adobe fixes this problem in the next Flash 9 update.



Yep that’s just great!!! I’ve seen it…. It’s sucks man…!!
I have the same problem with Papervision.
My flash is using more and more memory…
I removed my object from the displayList, i removed the listeners (with weakreference), i removed every link i could find. But the problem is still here
Check the 2nd update in the post for a solution/workaround (whatever you want to call it
)!
Thanks a lot !
In your update 1, how you diposed the bitmap data… Thanks! By the way, I have the same problem with you, but mine seems to be more terrible! I ran my test in IE browser, the memory still increase…
I was just going to post the solution as I ran your example in flex builder and it worked fine
btw , can you fix the url in the second update?
Thx
The link isn’t working .
By the way, if find that :
http://www.adobe.com/support/documentation/en/flashplayer/9/releasenotes.html
Developers should not rely on garbage collection if immediate clean up of active objects, such as display objects, streams and media, is expected. Use the appropriate ActionScript 3.0 APIs (close, removeEvent Listener, etc.) to get immediate behavior when cleaning up active objects.
Are they joking ?
Fixed the link…
I’ve spent all day trying to work out why my Class definitions weren’t being garbage collected. I read this, tried running my app in Firefox instead of the IDE and it worked! Thankyou very much!!
Same problem still exists in projectors. Dont know which versionen fixes this issue. I wrote a complex structure which increases memory because the garbage collector doesnt work like expected. Finally Ive found the problem with the Loader-Class, but no solution.
This bug is fixed in Flash IDE Version 9.0.2.
Stop! This “bug” is still not fixed satisfyingly. Ive played around with the Loader-Class (I have coded a kind of HTML-renderer) and made the following oberservations:
* With 9.0.2 loading and removing simple images (jpg) with garbage collector works fine.
* It doesnt matter if you remove any event listeners (Event.COMPLETE), but its always a good idea to do that.
* You dont need to unload the Loader.
* You dont need to remove the Loader (or its content) from its parent.
* It DOES MATTER which kind of SWF you load. I load a third party SWF-file into my HTML-engine and the garbage collector was not able to remove this file from the memory. I built a test SWF-file in AS3 without import protection and it works! Dont know how to check this in the future, the SecurityErrorEvent hadn’t dispatched. But maybe using the LocalConnection is a solution.
* Its RECOMMENDED to start the garbage collector manually. I call the function every 3 seconds with an interval for now.
Code for the garbage collector:
—–
import flash.net.LocalConnection;
import flash.system.System;
private function collectGarbage():void {
trace(“memory before: ” + (System.totalMemory/1024) + ” kiB”);
try {
new LocalConnection().connect(‘foo’);
new LocalConnection().connect(‘foo’);
} catch (e:*) {}
trace(“memory after: ” + (System.totalMemory/1024) + ” kiB”);
}
—–
I’m having the same problem with the memory going sky high in the browser. Did anyone come up with a solid solution for this? It’s my understanding that each swf is being loaded and never cleared from the memory. I’ve been working on this all day with no solution yet
problem site:
http://www.troylawrence.com/mb2008/tile_as3.html