Memory leak when cloning and disposing of a mesh.

Software: Away3D 4.x

abpyles, Newbie
Posted: 06 June 2014 07:38 PM   Total Posts: 4

I am working on a project that requires that I clone a mesh repeatedly and then dispose of the clones. There seems to be something loitering around in memory after I dispose of the clones of the mesh, which is causing memory usage to slowly creep up.

I load my mesh in using a Loader3D like this:

meshLoader = new Loader3D(false);
meshLoader..addEventListener(AssetEvent.ASSET_COMPLETEmeshLoaded,false,0,true);

private function 
meshLoaded(event:AssetEvent):void{
   
if (event.asset.assetType == AssetType.MESH
   
{
    meshLoader
.removeEventListener(AssetEvent.ASSET_COMPLETEmeshLoadedfalse);
    var 
mesh:Mesh event.asset as Mesh;
    
mesh.castsShadows false;
    
mesh.material meshMaterial
   
}
  } 

Once I have the mesh loaded in I create a clone and add it to an array of clones like so:

meshClone originalMesh.clone() as ObjectContainer3D;  
cloneArray.push(meshClone);
_view.scene.addChild(meshClone); 

Then when I want to remove a clone from the front of the array I do it like this:

view.scene.removeChild(cloneArray[0]);
cloneArray[0].disposeWithChildren();
cloneArray[0].disposeAsset();
cloneArray[0].dispose();
cloneArray.shift(); 

If I do this for a large number of clones and then remove all the clones using this method and then force garbage collection the memory usage will still be noticeably larger than before.

   

Avatar
theMightyAtom, Sr. Member
Posted: 09 June 2014 06:13 PM   Total Posts: 669   [ # 1 ]

If they are identical objects, try making a variable of your mesh data (materials, etc.). In this way they are reused. You can have thousands of the same mesh without using hardly any extra memory.

Good Luck!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X