[Memory Issue] dispose a mesh and load a new one

Software: Away3D 4.x

Mael, Newbie
Posted: 29 June 2012 10:15 AM   Total Posts: 5

Hi !
First, sorry for my english.

As you know, I’d like to dispose a mesh and replace it. In my example I tried to replace it by the same one. I used 2 functions :
first one:

public function disposemodel(model:Loader3D)
  
{
   
var j:int 0;
   var 
numChil:uint model.numChildren;
   var 
mesh:Mesh;
   var 
texMat:TextureMaterial;
   for (
0numChil2; ++j)
   
{
    mesh 
Mesh(model.getChildAt(j));
    
texMat mesh.material as TextureMaterial;
    
texMat.texture.dispose();
    
texMat.dispose();
    
texMat=null;
    
mesh.geometry.dispose();
    
mesh.dispose();
    
model.removeChild(mesh);
    
mesh=null;
   
}

  } 

and this one :

//var tete: Loader3D=new Loader3D();

public function loadmodel():void
 {
  tete
.addEventListener(LoaderEvent.RESOURCE_COMPLETEonModelLoaded);
  
tete.load(new URLRequest(obj.addressmodel));

  
}

function onModelLoaded(LoaderEvent):void
{

 tete
.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonModelLoaded);
 
_view.render();

I created a button:

disposemodel(tete);
 
loadmodel(); 

Each time I click the button, memory “grows up” :s . First time my mesh is replaced, but at the second click, all the other children of the container 3d disappear (the replaced mesh is still visible).what’s going on?


Thank you for any help you may provide to me.

   

Shegl, Sr. Member
Posted: 29 June 2012 07:03 PM   Total Posts: 134   [ # 1 ]

dispose bitmap data. and use the GC Trick:

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

Mael, Newbie
Posted: 29 June 2012 11:19 PM   Total Posts: 5   [ # 2 ]

thanks, I forgot to dispose bitmapdata. But all other children of container3d still get invisible at the second clic. It’s quite annoying.

I refreshed all textures but ... didn’t work.

   

Richard Olsson, Administrator
Posted: 30 June 2012 09:27 AM   Total Posts: 1192   [ # 3 ]

I’m not sure I understand. In your code, you loop over all the children and remove them. Why wouldn’t they disappear? That seems perfectly expected to me, unless I’m misunderstanding what you’re trying to do.

As for things not being disposed correctly. By default Loader3D uses the AssetLibrary (you can change this using a flag in the constructor.) This means that the library will hold references to all of these objects. If you’re not using the asset library for anything else, just go ahead and disable it (in the Loader3D constructor) or you have to remember to dispose all assets in the AssetLibrary as well.

   

Mael, Newbie
Posted: 02 July 2012 06:09 PM   Total Posts: 5   [ # 4 ]

Thanks a lot, disable AssetLibrary solved some of my problems but models still vanish at the second “click”. I guess the function disposemodel() is not correct because If I don’t dispose previous model, the other container’s children don’t disappear.

EDIT : I found where is the problem:

texMat.dispose();

dispose works well without this line. I don’t know why.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X