Loader3D Memory Issue?

Software: Away3D 4.x

Tom.de, Newbie
Posted: 21 May 2012 11:27 AM   Total Posts: 30

Hey everyone.

I am working with Away3D 4 for about 2 months now and I seem to have an issue with my memory management.
I am at this point not sure if this is simply a problem of me not understanding some of the basic things I should be doing or if it is something else.

I am loading a model via Loader3D and add it to the root:

m_Loader3D = new Loader3D();
m_Loader3D.addEventListener(LoaderEvent.RESOURCE_COMPLETEOnResourceComplete); 
m_Loader3D.addEventListener(LoaderEvent.LOAD_ERRORonLoadError);
m_Loader3D.loadData(new model());
m_SceneRoot.addChild(m_Loader3D); 

Once OnResourceComplete is called I add textures and remove the event listener from m_Loader3D.
This works all fine. The model is being rendered correctly.
Then, at some point, I want to delete it. This is how I do it.

m_SceneRoot.removeChild(m_Loader3D);
m_Loader3D null

If my understanding is correct, the garbage collector should now pick up the loose ends and delete it from memory?

However, if I check the memory consumption (firefox-plugin-container) then nothing is ever freed up. If I repeat above steps then every time I load the model again more memory is used up while setting the loader3D to null will never free up anything.

I have set Loader3D(false) as well to make sure the AssetLibrary is not used but to no avail.

Am I missing something incredibly basic? I thought the GC will free up anything that isn’t referenced anymore?

Edit:
If I repeat above steps continuously memory will continue to grow until it will crash.

   

Griallia, Newbie
Posted: 13 June 2012 07:02 PM   Total Posts: 3   [ # 1 ]

m_Loader3D = new Loader3D();
m_Loader3D.addEventListener(LoaderEvent.RESOURCE_COMPLETE, OnResourceComplete);
m_Loader3D.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError);

m_Loader3D.loadData(new model());
m_SceneRoot.addChild(m_Loader3D);

See the bold part? You never got rid of the event listeners and therefore it’s still technically in use and can not be garbage collected. You have to remove the event listeners or at least set them to use weak links.

Removing:

m_SceneRoot.removeChild(m_Loader3D);
m_Loader3D.removeEventListener(LoaderEvent.RESOURCE_COMPLETEOnResourceComplete); 
m_Loader3D.removeEventListener(LoaderEvent.LOAD_ERRORonLoadError);
m_Loader3D null

Weak Links:

addEventListener(FooEvent.LUCKNLOLZbarFunctionfalse0true

Necro? yes, but it contains helpful information.

   

Tom.de, Newbie
Posted: 14 June 2012 12:33 PM   Total Posts: 30   [ # 2 ]

Hey,

thanks for your reply.
As mentioned in my first post, I do actually remove the event listeners in “OnResourceComplete” or when the object is destroyed before “OnResourceComplete” is called.
That’s what I found so confusing in the first place. smile

However, I haven’t tried weak listeners yet. I shall give that a shot.

   

Shegl, Sr. Member
Posted: 14 June 2012 01:34 PM   Total Posts: 134   [ # 3 ]

Tom.de also u can force to clean sweap GC by bug:

try {
       
new LocalConnection().connect('foo');
       new 
LocalConnection().connect('foo');
      
catch (e:*) {} 
   

Richard Olsson, Administrator
Posted: 16 June 2012 02:33 PM   Total Posts: 1192   [ # 4 ]

If you are getting textures, geometry et c from your load, you need to manually and explicitly call dispose() on those or their GPU resources (and their representations on the CPU) won’t be freed. Just removing the container from the scene graph is not enough.

   

Tom.de, Newbie
Posted: 18 June 2012 08:59 AM   Total Posts: 30   [ # 5 ]

Thanks for your reply. I think this might actually be my problem. After doing some tests, memory is used up as soon as the object is actually drawn on screen but after that it is never freed (despite deleting, garbage collecting etc.).

So when I need to destroy my m_Loader3D object, I need to dispose geometries and textures manually?

for (var int 0m_Loader3D.numChildren; ++i)
{
 Mesh
(m_Loader3D.getChildAt(i)).material.dispose();
 
Mesh(m_Loader3D.getChildAt(i)).geometry.dispose();

Or would it be sufficient to just call dispose on the actual mesh since it holds the geometry and material? (which is what I currently do, it does not seem to be enough though. (looking at the code, mesh dispose just sets material and geometry to null while the individual dispose methods do a lot more) So maybe combine that with the above solution?

for (var int 0m_Loader3D.numChildren; ++i)
{
 Mesh
(m_Loader3D.getChildAt(i)).dispose();

Futher info:
The material itself is added in “onResourceComplete”. The texture is an embedded texture. This is how it looks:

mesh.material = new TextureMaterial(new BitmapTexture(new embeddedTexture().bitmapData)); 

Many thanks for having a look at this. I’m still wrapping my head around this whole GC thing.

   

Richard Olsson, Administrator
Posted: 18 June 2012 09:03 AM   Total Posts: 1192   [ # 6 ]

The basic principle is that you need to dispose everything that you have a created, either through code or through loading. Things that Away3D has created internally (e.g. buffer objects, bounding volumes) will be disposed as part of their containing object (in this case Geometry.)

Bottom line is, you need to dispose both the Mesh, the Geometry, the MaterialBase (e.g. TextureMaterial) and any textures that you have. This is because Away3D cannot (or rather, does not try to) know whether you are re-using these or planning to re-use them across several meshes/materials.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X