memory management - very critical stuff

294 views
Skip to first unread message

claudiul25

unread,
Oct 19, 2009, 4:06:03 AM10/19/09
to away3d.dev
i have a project that loades and unloades diferent 3d applets done
with away3d.

the thing is that when i switch from one to another, the memory
increases.

i know that even if you remove objects with removeChild they still
exist if there are references to it.

when i remove the 3dapplet from stage, i call a destructor

(addEventListener(Event.REMOVED_FROM_STAGE, destructor3d) which is
actually called

function destructor3d(e:Event):void
{
away3dHolder.removeChild(view);
removeChild(away3dHolder)
if (spherecontainer2['planet2']) spherecontainer2.removeChild
(planet2)
if (table) removeChild(table)
if (table2) removeChild(table)
if (scene['sun']) scene.removeChild(sun)
scene.removeChild( skybox );

spherecontainer.removeChild(planet1)
scene.removeChild(spherecontainer);

scene.removeChild(spherecontainer2);
scene.removeChild(centerPlane);

trace("destructor")
scene = null
camera = null
view = null;
lastPanAngle = lastTiltAngle = null;

current_obj = null

planet1material = planet2material = null
skyboxmaterial = null
sunmaterial = null
bfmaterial1 = bfmaterial2 = null

planet1 = planet2 = sun = null
centerPlane = null
spherecontainer = spherecontainer2 = null
skybox = null
p1 = p2 = null

away3dHolder = null

removeEventListener( Event.ENTER_FRAME, render );
stage.removeEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
stage.removeEventListener( MouseEvent.MOUSE_UP, onMouseUp );
stage.removeEventListener(MouseEvent.MOUSE_WHEEL, fzoom);
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
stage.removeEventListener(Event.RESIZE, resizeHandler);
}

my question is why is my memory still increasing ? (a similar
destructor in used in the other 3d applet)

does the view object have a similar destructor that cuts all
references of their children? this is critical stuff

ben

unread,
Oct 19, 2009, 4:31:25 AM10/19/09
to away3d.dev
HI,
what version of away are the applets made of ?

claudiul25

unread,
Oct 19, 2009, 4:33:08 AM10/19/09
to away3d.dev
it's the latest from svn,

ben

unread,
Oct 19, 2009, 7:00:56 AM10/19/09
to away3d.dev
Wish one 2.x, 3.x, lite ??

Michael Iv

unread,
Oct 19, 2009, 7:02:23 AM10/19/09
to away3...@googlegroups.com
What??

ben

unread,
Oct 19, 2009, 7:11:40 AM10/19/09
to away3d.dev
sorry,
what version of away3D for the scenes you load :
2.4,3.4, away3Dlite ????

Michael Iv

unread,
Oct 19, 2009, 7:43:26 AM10/19/09
to away3...@googlegroups.com
3.4 but I found the Catch And it worth to spread in some article on Away 3.4 Install. The thing is when you use FlexLibrary Project as I do for my AS classes it is not enough to
change to globalplayer.swc 10 but you also need to go to  the Flex Library project folder and to open  file .actionScriptProperties in it you must change htmlPlayerVersion="9.0.0" to  10.0.0 . then the Library will compile for API 10 ,otherwise you continue getting Vector errors.

claudiul25

unread,
Oct 19, 2009, 7:44:18 AM10/19/09
to away3d.dev
away3d 3.4

ben

unread,
Oct 19, 2009, 8:07:25 AM10/19/09
to away3d.dev
To both Michael:

your topic is appearing in another topic.. don't know if it could be
fixed, but I answer you from
claudiul25 topic about memory management !!!

;-)

ben

unread,
Oct 19, 2009, 8:12:28 AM10/19/09
to away3d.dev
Michael, I allowed myself to copy your fix in your topic, in sort that
people could find it more easily.

Michael Iv

unread,
Oct 19, 2009, 8:45:15 AM10/19/09
to away3...@googlegroups.com
You always welcome

claudiul25

unread,
Oct 21, 2009, 3:57:01 AM10/21/09
to away3d.dev
allright, but that still doesn't answer my question. how soon will
there be a good memory manangement in away3d?

ben

unread,
Oct 21, 2009, 5:31:03 AM10/21/09
to away3d.dev
Yes, back to your question ;-)

So ghere I start again, what version of away3D are the applets made
of ?
do you also destroy your loader ?
what does your System.gc(); gives as results ?
Try clear the view : view.clear();

claudiul25

unread,
Oct 21, 2009, 5:53:10 AM10/21/09
to away3d.dev
away3d 3.4 is the engine version, i destroy the loader, and also run
System.gc, but the memory increases constantly,

i didn't know about view.clear() . i'll try it and hope it works

claudiul25

unread,
Oct 26, 2009, 6:53:49 AM10/26/09
to away3d.dev
sory for all these questions guys, but i'm stuck with my project if i
don't implement a good memory management.

in essence i want to know how do you erase from memory all the assets
(bitmaps, varibles, eventlisteners) used in a 3d swf that you don't
use anymore (you unload it)

i'm sure that it's implemented in the away3d library, but it's not
that well documented.

thanks.

Rob Bateman

unread,
Oct 30, 2009, 2:35:49 PM10/30/09
to away3...@googlegroups.com
Hey Claudiul25

hmm, this is always a problem with a large project such as yours, bt
the cause of the memeory problem is sometimes difficult to trace,
regardless of memory kill-switch techniques.

what i would suggest, if you are still having problems, is to try and
isolate the behavior of the memory in a simple class. this process
will not only help our debugging process, but help you pinpoint the
precise area that is causing problems in your application. armed with
that, i'm sure we can come to a solution for your memory management
issues.

However, if you are out of time for this particular project, one
things that never fails is an actionscript-triggered page refresh.
Sometimes the process is too complex to accurately trace, and when
time is a pressure, this can be an effective option (although hardly
elegant) to memory problems.

Rob

--
Rob Bateman
Flash Development & Consultancy

rob.b...@gmail.com
www.infiniteturtles.co.uk
www.away3d.com

claudiul25

unread,
Oct 31, 2009, 7:06:23 AM10/31/09
to away3d.dev
thanks Rob for your assistance. but this is an important issue.

allright, so i made a basic example. create and destroy a 3d scene.
you have 2 buttons to create and destroy a scene, and a textfield that
shows the current memory.
the behaivor of the destructor is not what i expected to be. although
i set view.clear(), removechild(objects) and removeChild(view) but the
memory level doesn't return to the initial one.

i hope the example is good, though it's very raw.

the file is memorymanagement.as

Rob Bateman

unread,
Oct 31, 2009, 8:31:14 PM10/31/09
to away3...@googlegroups.com
Hey claudiul25

thanx for the example! I'm sure it will help debug some of these
memory issues - i will have a look the first chance i get

cheers

Rob

claudiul25

unread,
Nov 16, 2009, 9:10:33 AM11/16/09
to away3d.dev
i've run some tests with flex profiler and it seems that something
isn't erased in DrawTriangle, UV and Face classes

claudiul25

unread,
Nov 16, 2009, 9:13:24 AM11/16/09
to away3d.dev
i 'm trying to get into those classes but i don't know how from my top
class, or from the view class. is there any way i can do this, to
inspect the content of those classes?

i'll post some snapshots of flex profiler on creating and destroying a
scene with 4 spheres in it (flexprofiler_snapshot)

claudiul25

unread,
Nov 16, 2009, 11:47:03 AM11/16/09
to away3d.dev
i want to repair some memory leaks but i don't know anything about the
engine
all i know is there are coming from DrawTriangle, UV and Face classes

can please somebody explain to me if DrawTriangle is a used for every
object in the scene by the respective object, or by the scene or view

thanks, i really need some help here, and is for the benefit of many,
not just me

Rob Bateman

unread,
Nov 16, 2009, 6:44:02 PM11/16/09
to away3...@googlegroups.com
Hey claudiul25

i'm afraid i've not been able to take a look at the memory leak example you sent yet, but i do realise this is of high priority to a lot of people.

the drawtriangle currently represents a projected triangle before it is drawn to screen. because a lot of these object are created they are stored in an object pool inside the utility class DrawPrimitiveStore. there is a DrawPrimitiveStore class for every view created. when a drawtriangle is no longer being used, it returns to the pool, and when one is required it is taken from the pool unless the pool is empty.

UV and Face classes are geometry data classes stored in arrays in the geometry class. In Away3d, this data is atttempted to be separated from the draw data, so that if and when a geometry class is no longer referenced, it's contents can be deleted in a GC sweep. however, if you are experiencing rising UV and Face object instances in the profiler, then some reference is stopping these classes from being GC'd. it is possible that a material object is storing the data and not giving it up because the material is still being used, however if you are replacing whole objects this shouldn't be the case.

If you want to help, i can answer questions related to the structure of data in Away3d but unfortunately i am having trouble finding time to dedicate to debugging the problem right now. If you can afford to wait, we will try and address the issue asap. part of the problem is that GC issues are one of the hardest things to deal with in Flash, as i'm sure you are all to aware! I'll let you know when we have any progress on this issue

atb

Rob

elguapoloco

unread,
Nov 16, 2009, 7:25:22 PM11/16/09
to away3d.dev
Hi,

Might be off topic, but if this is memory leaks due to loaded and
"unloaded" content I would look at the following:
http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html

//////// START QUOTE ////////

Work-Arounds and Strategies
There are four main things you can do to address these issues now:


1. Make sure that you are always removing timer and enterframe
event listeners in content you may want to load into a larger
application. Also, try to avoid stage listeners where possible, and
remove them immediately when you are done with them.

2. Expose a standard API in your SWFs that allows other SWFs to
tell it to clean up and stop executing. This way, the loading
application can call this method (within a try/catch block) before it
unloads any content. I would suggest a .halt() method, backed by a
listener for a "halt" event through sharedEvents.

3. You can load content SWFs from a subdomain. This will place it
into a security sandbox implicitly.

4. Load content into a div layered over your main application. This
isn't a great option, but it addresses almost all of the issues.

//////// END QUOTE ////////

I had a memory leak issue in a recent project where I loaded an Away3D
based quiz into a main site swf. After some testing I realized the
memory would increase by loading/unloading images. I looked around and
Grant Skinner's article was a sad realization that GC in AS3 isn't up
to par with what it was in AS2 for loaded content!

I ended up making the quiz a persistent element, which worked in that
context. But this was by no means a proper solution.

Cheers,

Jerome.

claudiul25

unread,
Nov 17, 2009, 7:02:57 AM11/17/09
to away3d.dev

thanks rob

i'd be more than happy to help to solve memory leaks in away3d, i have
no choice , my project depends on it :), but i need your help

if you can explain the engine structure in more depth, that will ease
my work a lot, i've been trying to follow the logic behind it but it's
a bit to much for me.. i have a base knowledge of screengraphs,
translators and other basic terminology but i can't put them together.
so i'm willing to fix those memory leaks but you have to help me
understand the mechanism. thanks

Ludwig

unread,
Nov 19, 2009, 4:51:31 AM11/19/09
to away3d.dev
Hi, any updates on this? Have the same problem when I remove a 3d
scene/view - it doesn't get garbage collected. Using the latest fp10
version.

Could it be related to a know flash bug?

* graphics.clear();
problem to gc with beginBitmapFill if you dont clear the graphics
on remove? Know I saw somthing abut it a couple of days ago.

* buttonMode = true;
http://joshblog.net/2009/04/30/combine-buttonmode-true-and-a-mouse-click-to-leak-memory/


/Ludwig

claudiul25

unread,
Nov 19, 2009, 11:30:31 AM11/19/09
to away3d.dev
i think that the bug with buttonmode was fixed

i just profiled my project which had some movieclips with buttonmode
true and they got dumped by GC

i use fp 10.0.32.18

the rest of the problems are related to the whole arhitecture of the
engine, it does have some serios mem leaks, which i cannot entirely
stop

Reply all
Reply to author
Forward
0 new messages