Memory Leak Help

Software: Away3D 4.x

Aphex, Newbie
Posted: 23 August 2011 05:11 PM   Total Posts: 1

Hey guys I hope I am just doing something wrong as we would REALLY like to use Away3d 4.0 in a big project that we are diving into. Here is the problem. I cannot get the memory to drop, no matter what I try when I load -> unload -> load a Away3D scene the memory always rises. Here is what I am doing.

I have a class that simply extends Sprite. When added to the stage it creates a View3D, Object3DContainer, 3 Color Materials, 2 Spheres and 1 Cube and 2 Listeners (Enterframe and Resize). Applies the Materials to those objects.

Added To Stage Code

_view = new View3D();
_view.antiAlias 4;
this.addChild(_view);

addEventListener(Event.ENTER_FRAMEonEnterFrame);
stage.addEventListener(Event.RESIZEonStageResize);

_ctr = new ObjectContainer3D();
_view.scene.addChild(_ctr);

var 
green:ColorMaterial = new ColorMaterial(0x00FF00);
var 
red:ColorMaterial = new ColorMaterial(0xFF0000);
var 
blue:ColorMaterial = new ColorMaterial(0x0000ff);

_ctr.addChild(new Sphere(green)).= -200;
_ctr.addChild(new Sphere(red)).200;
_ctr.addChild(new Cube(blue10010010011725false)); 

When removed from stage the class Removes all children, removes the 2 Listeners, calls dispose on the view, nulls the view, calls dispose on the ObjectContainer3D.

_camController.destroy();
_ctr.dispose(true);

while(
this.numChildren >0this.removeChildAt(0);

removeEventListener(Event.ENTER_FRAMEonEnterFrame);
stage.removeEventListener(Event.RESIZEonStageResize);
_view.dispose();
_view null


Finally I have a Shell application that has a simple timer. Every 30 seconds it unloads the AwayDemo waits 10 seconds then loads a new instance.
Even in such a small simple demo with 3 basic materials and objects the memory just increases over time. If i let this run overnight the next day the player is totally trashed and over a gig is used.

The project we are looking to get into involves long runs of the application, and moving back and forth between a screensaver and the application when users are interacting with it. Am I missing something simple to clean up the memory on this project?

thanks a lot!
-ross

 

   

Avatar
Choons, Sr. Member
Posted: 23 August 2011 07:06 PM   Total Posts: 281   [ # 1 ]

seems there may indeed be memory leak issues with Away3D. Give this a try as well:

http://gskinner.com/blog/archives/2006/07/as3_weakly_refe.html

   

Richard Olsson, Administrator
Posted: 24 August 2011 07:10 AM   Total Posts: 1192   [ # 2 ]

There might be memory leaks, and if you are able to narrow it down it would be great if you could file an issue report.

In the meantime, why are you completely destroying and then recreating everything? Why not just re-use those objects for which it makes sense (which is good practice anyway)?

   

Aphex, Newbie
Posted: 24 August 2011 03:34 PM   Total Posts: 1   [ # 3 ]

Actually going through my project and setting Weak References on All listeners did help considerably. I was not seeing memory increase in my smaller demos.

In bigger demos using normal maps and complex lighting I am seeing the memory increase by a meg or so each time. I am trying to track down exactly what is getting held onto. From what I can tell so far it appears to be vectors being held in memory.

My current test goes like this. Shell creates a new AwayDemo and adds it as a child. Delays for 15 seconds then removes it. Delays again then adds it. This happens 3 times. After the Demo is removed for the final time I capture a memory snapshot. I am using IntelliJ and the Actionscript Memory profiler plugin (http://plugins.intellij.net/plugin/?id=5351)

At that point 56 Vector Objects remain eating 1909768 bytes. Almost all of this is coming from OBJParser.as.

TranslateMaterialGroup function lines 325,326 & 327 where a normals, verticies, and uvs Vector is created. I am wondering if somewhere these vectors are being held onto?

Though I agree that destroying and recreating the whole scene isn’t normally the best way to go about things and reuse is much better. The project I am working on will be an installation. The application will be moving back and forth to a screensaver/idle state. Every time it comes out of that state the 3D objects that will be on screen will change. They are dynamically generated based on user interaction and creation at another terminal. So there isn’t going to be as much to “reuse” as every time someone comes into this application the content will be slightly different. I could attempt to cache every visitors 3d creation but seeing that this could pull in a lot of people I wouldn’t want to store everything in memory like that.

Right now I am just trying to have the best control over the memory as possible as this application will be running for long stretches of time and I simply can’t have it creeping up. I figure once I know how to control all aspects of cleanup I can then look at where I can gain efficiency with caches.

Any more ideas or advice would be greatly appreciated, thanks a lot for the tip already though it did help considerably!

-ross

   

Richard Olsson, Administrator
Posted: 24 August 2011 03:44 PM   Total Posts: 1192   [ # 4 ]

Thank you! You have already helped a lot by benchmarking and trying to narrow down the problem. Have you tried using another format, in case the OBJParser is indeed what’s causing the problem?

   

Avatar
Choons, Sr. Member
Posted: 25 August 2011 05:07 PM   Total Posts: 281   [ # 5 ]

some nice sleuthing there, Ross. I’ve been curious to try this:


http://www.buraks.com/azoth/


FlashDevelop even has a bundled plugin for it now. Won’t stop a true memory leak but might clean up any intrinsic Flash memory problems

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X