Completely unload model and scene from memory

Software: Away3D 4.x

surferdave, Newbie
Posted: 23 September 2013 07:23 PM   Total Posts: 3

Hi All
Pretty new to this 3d stuff so bare with me.  I am working on a project lets call it model viewer.  I need to be able to load models and then unload them.  Due to the nature I need the model completely removed from memory.  I seem to be removing a fair amount of memory but not all of it.  I start with 27mb before loading model.  I hit 89mb with loaded model.  Then after running destroy() I end up with 59mb.  Any help would be great.

_view = new View3D();
   
_view.antiAlias 2;
   
_view.backgroundColor 0x333333;
   
   
_camera _view.camera;
   
_camera.lens = new PerspectiveLens();
   
_camera.lens.near 10;
   
_camera.lens.far 15000;
   
   
_camera.= -122.74610137939453;
   
_camera.184.41575622558594;
   
_camera.2928.63330078125;
   
   
_group = new ObjectContainer3D();
   
_view.scene.addChild(_group);
   
   
direction = new Vector3D(-1, -11);
    
   
   
_cameraController = new HoverController(_cameranull150102000);
   
_cameraController.wrapPanAngle true;


Loader3D.enableParser(AWD2Parser);
   
_loader = new Loader3D(false);
_loader.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete);   _loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE,onResourceComplete);
_loader.load(new URLRequest(_path+_url), new AssetLoaderContext(true));

private function 
onAssetComplete(ev AssetEvent) : void
  {
   trace
("asset "+ev.asset)
   if (
ev.asset.assetType == AssetType.MESH{
    
    
    _mesh 
Mesh(ev.asset);
    
_texMat _mesh.material as TextureMaterial;
    
    if (
_mesh.material == null || (_texMat && _texMat.texture == null))
     
_mesh.material = new ColorMaterial(Math.random() * 0xffffff);
   
}
  }
  
  
  
private function onResourceComplete(ev LoaderEvent) : void
  {
   _camera
.addEventListener(Object3DEvent.POSITION_CHANGEDchangePosition)
   
_group.addChild(_loader);
   
_camera.lookAt(_loader.position);
   
   
   
  
}

public function destroy():void{
   this
.removeEventListener(Event.ENTER_FRAMEonEnterFrame);
   
this.removeEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
this.removeEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
   
_loader.removeEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
_loader.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
this.removeEventListener(Event.MOUSE_LEAVEonStageMouseLeave);
   
_camera.removeEventListener(Object3DEvent.POSITION_CHANGEDchangePosition);
   
   
disposemodel(_loader)
   
   
   
   try 
{
    
new LocalConnection().connect('foo');
    new 
LocalConnection().connect('foo');
   
catch (e:*) {}
  }
  
  
public function disposemodel(model:Loader3D):void
  {
   _group
.removeChild(_loader);
   
_view.scene.removeChild(_group);
   
_view.camera.disposeAsset();
   
_view.camera.dispose();
   
_camera.disposeAsset();
   
_camera.dispose();
   
   while (
_view.numChildren 0){
    _view
.removeChildAt(0);
   
}
   
   _view
.dispose();
   while (
_loader.numChildren 0){
    _loader
.removeChild(_loader.getChildAt(0));
   
}
   _loader
.disposeAsset();
   
_loader.dispose();
   
   
_mesh.geometry.dispose();
   
_mesh.dispose();
   
_mesh null;
   
_texMat.texture.dispose();
   
_texMat.dispose();
   
_texMat null;
   
   
this.removeChild(_view)
   
   
  
   

Avatar
SharpEdge, Member
Posted: 24 September 2013 07:57 AM   Total Posts: 94   [ # 1 ]

Same old story, have you tried to force GC? Because maybe you are disposing correctly but GC runs later. If you are sure that something is stuck in memory use profiler and the loitering object functionality to find out what’s remaining in memory.

   

surferdave, Newbie
Posted: 24 September 2013 02:49 PM   Total Posts: 3   [ # 2 ]

Yes, I do force gs its in the code above.  I have also let it run for an extended period to see if it clears out on its own.

I think more what I am asking, since I am new to away3d is am I correctly disposing of the model, assets, view etc.  Is there a better way? Am I maybe not disposing of something or not doing it correctly correctly?  I read something about an assetlibrary and a few other things that I dont understand or could not get to work.

   

Avatar
SharpEdge, Member
Posted: 27 September 2013 07:41 AM   Total Posts: 94   [ # 3 ]

The AssetLibrary is used to store loaded models, but in your code you’re not using it because you instatiate Loader3D with “new Loader3D(false)” so you don’t have to dispose the AssetLibrary in this case.

   

surferdave, Newbie
Posted: 27 September 2013 04:54 PM   Total Posts: 3   [ # 4 ]

thanks, is there any benefit in my case to using the AssetLibrary?  is the rest of my dispose code good?  am I missing or could improve anything?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X