Pages: [1]
  Print  
Author Topic: AS3: Important To Know About Unloading Pages/Assets  (Read 6432 times)
steven
Gaia Author
Administrator
Gaia Evangelist
*****
Posts: 3871


gaiaframework
WWW
« on: April 07, 2008, 03:21:22 PM »

http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html

"Flash Player 9 has a very dirty secret. It doesn't even try hide this dirty secret, but it's still not that widely known. You see, Flash Player has severe problems with separation anxiety - once it's loaded some content, it has a really hard time ever letting it go. Technically speaking, it is extremely difficult to make Flash Player 9 unload ActionScript 3 content."

Required reading if you're developing with Gaia AS3.
« Last Edit: July 11, 2008, 02:43:33 PM by steven » Logged

Steven Sacks | Gaia Author
Please support Gaia by donating to the project!  Smiley
steven
Gaia Author
Administrator
Gaia Evangelist
*****
Posts: 3871


gaiaframework
WWW
« Reply #1 on: May 24, 2009, 07:55:40 AM »

"If unloading does not work"

There's no way to know if unloading does not work. GC does not run instantly, and the very nature of putting anything in place to check if something is unloaded means you're keeping a reference to it, and therefore it can't unload.

You have to clean up your swfs.  There's no way around it.

Also, the debug player is MUCH slower than the regular player.  You should never judge your site's performance based on the debug player.
« Last Edit: May 24, 2009, 09:59:16 AM by steven » Logged

Steven Sacks | Gaia Author
Please support Gaia by donating to the project!  Smiley
AlanJhonnes
Gaia User
**
Posts: 10



WWW
« Reply #2 on: January 15, 2011, 04:13:47 AM »

You just need to make sure your pages and especially custom loaded SWFs are being cleanned up with GC after they unload.
I personally have been using the Temple library to track both memory usage and all my Temple objects,making it easy to know when something is not unloading and when it is and giving you a help in cleanning your SWFs as well.Theres a thread about it in the forums, just look for it.
In fact, my most recent site made heavy usage of loaded content, including games, and I have no problems whatsoever because I made sure all games and pages can and do get garbage collected.

I see the div aproach as not viable, first because its alot of hack and to actually manage your site in diferent swfs/divs would be a pain. Hell, why would you even use Gaia for that is beyond me.
Second, because to having to render transparent SWFs on top of each other can reduce the performance, so even if you don't have memory leaks, you'll have a much more CPU/memory usage rendering those SWFs than if you were using the conventional method of simply cleanning the objects for GC.
Third, reusability. How making bloated code that already have a problem not getting GC'd is reusable?

No wonder everyone keeps saying flash sucks because it consumes alot of memory, its because alot of developers don't give a damn about memory management and thats not flash's fault, in other languages you already have to explicit clear the memory. Get used to it, don't hack your way around.
« Last Edit: January 15, 2011, 08:21:07 AM by steven » Logged
pkaufmann
Gaia Novice
*
Posts: 6


« Reply #3 on: April 01, 2011, 07:00:22 AM »

You actually can force GC to run with the following method:
The snippet is from http://www.nbilyk.com/flash-garbage-collection.

      public function gcHack():void {
         // unsupported technique that seems to force garbage collection
         try {
            new LocalConnection().connect('foo');
            new LocalConnection().connect('foo');
         } catch (e:Error) {}
      }


I guess usually the GC is only called when the flash player needs to do it. This is the experience when progamming flash games. Actually the instant call of the gargage collection isn't needed at all. The regular GC already triggers quite often.
The important thing is: When deleting objects, remove all listeners referring to the object. Else this object won't be caught by the GC.
Logged
Markoner
Gaia User
**
Posts: 34



« Reply #4 on: April 01, 2011, 07:46:51 AM »

I think I've read somewhere that this does not work in release but only in debug.

I agree with you that listeners are the first cause of stuff not being GC'd.
To me all listeners should be added with the weak reference parameter set to true in addEventListener (this should be the default!).

Still I think it's a nightmare not to be able to just simply remove loaded content.
I recently had trouble with a games loading platform. For most of them (small ones) I was able to keep the memory low run after run.
But one of them was a bigger 3D stuff (using away3D lib) eating lots of Mo and CPU each time.
After searching for days I was able to reduce the effect but it's still not perfect.

No wonder everyone keeps saying flash sucks because it consumes alot of memory, its because alot of developers don't give a damn about memory management and thats not flash's fault, in other languages you already have to explicit clear the memory. Get used to it, don't hack your way around.

As an old C++ game developer I partly agree. But many flash developpers don't even know what is memory.
In other languages you allocate and deallocate memory explicitly. When you call delete/free memory just gets release (well or you get a crash  Wink).
In AS3 memory gets eat up insidiously and we don't have any tools (or clear clues of how) to free it. You can new but you can't delete.
We can even load big, complex, maybe third parties externals swf but we can't be sure to unload them. You can load but you can't unload.
I think it's a problem.


Logged
daival
Gaia Novice
*
Posts: 2


« Reply #5 on: May 03, 2011, 02:32:52 AM »

programming....   
Logged
Pages: [1]
  Print  
 
Jump to:  

TinyPortal v1.0 beta 4 © Bloc