texture memory leak

Software: Away3D 4.x

pquiring, Newbie
Posted: 18 November 2011 04:21 PM   Total Posts: 5

I’ve search everywhere and tried everything but can’t fix this.

If I create a simple onEnterFrame function as this everything is okay.

  private var _cube:Cube;
  private function onEnterFrame(ev : Event) : void
  {
    _view.render();
    _view.scene.removeChild(_cube);
    _cube.dispose();
    _cube = null;
    System.gc();
    _cube = new Cube();
    _view.scene.addChild(_cube);
  }

Running this is fine but as soon as I use “new Cube(myTexture)” the memory usage just keeps climbing.

What is the proper method of disposing an object with a texture?

I’ve tried using Away3d 4.0 and the new 4.0a in git as of today, both have the same problem. (Edit: for v4.0 I use dispose(true) )

I’m only using Flex SDK so I don’t have an expensive debugger to see where the problem is.

Thanks.

   

pquiring, Newbie
Posted: 18 November 2011 05:01 PM   Total Posts: 5   [ # 1 ]

I FIXED IT !!!!

Using v4.0 I changed the dispose() function in entities\Mesh.as so that it doesn’t dispose() the material but still calls dispose() on the _geometry.

So just comment out the _material.dispose() and it works like this:

  override public function dispose(deep : Boolean) : void
  {
  _geometry.removeEventListener(GeometryEvent.BOUNDS_INVALID, onGeometryBoundsInvalid);
  _geometry.removeEventListener(GeometryEvent.SUB_GEOMETRY_ADDED, onSubGeometryAdded);
  _geometry.removeEventListener(GeometryEvent.SUB_GEOMETRY_REMOVED, onSubGeometryRemoved);
  _geometry.removeEventListener(GeometryEvent.ANIMATION_CHANGED, onAnimationChanged);

  if (deep) {
  _geometry.dispose();

  if (_material) {
//    _material.dispose(true);  //don’t dispose, just reuse it later
    material = null;
  }
  }
  }

Enjoy!

   

Alex Bogartz, Sr. Member
Posted: 18 November 2011 09:11 PM   Total Posts: 216   [ # 2 ]

Maybe this is a situation better fixed by using an object pool?  Let’s say you want to create a bullet as a cube, just make a vector of cubes and recycle them.  This way, when you do need to totally zap a mesh, it will dispose the material?

Or are you saying we should never dispose materials?

   

pquiring, Newbie
Posted: 18 November 2011 09:27 PM   Total Posts: 5   [ # 3 ]

Ya, don’t dispose() the material but do the rest.

I think that dispose()ing a mesh should not dispose the material.  Let the user control that aspect.  But dispose()ing a mesh should get rid of all subGeometry (you wouldn’t reuse them).

The way it is in 4.0 it either only deletes the listeners (deep=false) or it deletes subGeo + material when deep=true.

In the example I gave you would need to delete the subGeo but not the material which is not possible with the library as it is now.  Memory leakage is unavoidable.

TTYL

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X