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_COMPLETE, meshLoaded,false,0,true);
private function meshLoaded(event:AssetEvent):void{
if (event.asset.assetType == AssetType.MESH)
{
meshLoader.removeEventListener(AssetEvent.ASSET_COMPLETE, meshLoaded, false);
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.