Memory leak

Software: Away3D 4.x

Avatar
Cheng Liao, Administrator
Posted: 09 August 2011 07:34 AM   Total Posts: 116

A ObjectContainer3D will not be used,I wan’t to destroy it.I remove it from and call dispose function ,but the memory is not be recycled.
Please download the example:
http://testserver.99gaming.net:9080/Main.as

   

Avatar
theMightyAtom, Sr. Member
Posted: 09 August 2011 07:55 PM   Total Posts: 669   [ # 1 ]

Could it be because you’re not calling the garbage collector, and Flash isn’t automatically calling it?

It’s been a while since I’ve come across this, but in the good old days I remember using

flash.system.System.gc();
flash.system.System.gc(); 

http://www.craftymind.com/2008/04/09/kick-starting-the-garbage-collector-in-actionscript-3-with-air/

I have no idea if GC is different in FP11 beta, but it’s something to try.

   

Somokon, Member
Posted: 09 August 2011 09:58 PM   Total Posts: 75   [ # 2 ]

I seem to have trouble getting the garbage collector to work as well.  Basically what I did to test was:

dictionary = new Dictionary(true); //Weak keys

mesh = new Mesh(materialgeometry); //or any primitive object
view.scene.addChild(mesh);

dictionary["target"mesh//Point the weak key to the object


onEnterFrame() {
    
if (timeElasped x{
        view
.scene.removeChild(mesh); //Remove the object from the scene
        
mesh null//Remove the mesh pointer
    
}

Now, as far as I understand, after ‘x’ time has elapsed, the Mesh object should now be eligible for garbage collection, as the only reference to it is the weak dictionary key.  So I then trace(dictionary[“target”]) at different times, yet even after the object is removed it is still referencing the object.

Anyone more experienced with the AS3 garbage collector know what is happening here?

I also had some listeners on the object, but I made sure to remove them as well.

   

jahiro, Newbie
Posted: 10 August 2011 12:19 AM   Total Posts: 3   [ # 3 ]

I’ve worked with the Flash GC player a lot in the past and the only way I’ve been able to force the GC to run is either:

a) Use the FlashBuilder Pro’s Profiling tool and click the little GC button
b) Use Grant Skinner’s LocalConnection GC technique here: http://gskinner.com/blog/archives/2006/08/as3_resource_ma_2.html

But to be honest, if you’re having to employ aggressive GC techniques like this, it’s likely that you may be trying to load/unload too much data at once. Flash’s GC works well, and GC is expensive so the player will only run it when necessary. My advice is to sit back and let the player do the GC for you, rather than forcefully invoking it.

   

Avatar
Cheng Liao, Administrator
Posted: 10 August 2011 01:46 AM   Total Posts: 116   [ # 4 ]

Flashplayer’s gc is ok.Please the example:
http://testserver.99gaming.net:9080/Main.as.flashtest

We don’t need to call the gc function.

   

Avatar
Alexander Seifert, Moderator
Posted: 10 August 2011 07:19 AM   Total Posts: 129   [ # 5 ]

I’m not sure how the Flash GC works, so I don’t trust it :D What I’ve noticed, however, is that it kicks in automatically every 1.5 seconds. It is also said that the GC doesn’t collect memory islands too big to be true. That’s why it’s best practice to nullify all references, regardless of non-interconnectedness to other memory islands.
Also very bad are event listeners, which are said to categorically prevent garbage collection, no matter what is listening to which event on whatever object.

Looking into the code of ObjectContainer3D.add/removeChild methods, during the add method, the child.scene property is set. However, in the remove method, it isn’t nullified.
Could it be possible that the ObjectContainer3D isn’t eligible for collection since it still has a reference to the scene object?

Looking into the constructor of Sphere, there is a number of event listeners being registered with the _geometry in the constructor of its base class Mesh. They seem never to be unregistered. Red flag! Red flag!

Regarding these events, they seem only to be used for communication between Geometry and Mesh. For performance reasons I’d recommend to refrain from using Flash’s native event dispatching system and replace it with a classic observer-pattern.

What are your thoughts?
Cheers!
Alex

 Signature 
signature_image

http://www.deltastrike.org

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X