brlrt / away3d

Automatically exported from code.google.com/p/away3d
0 stars 0 forks source link

View3D Memory Leak #104

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Away3DLite View3D has a memory leak by not removing the stage resize 
listener when the View3D is removed from the stage. 

To reproduce add multiple scenes using View3D and then remove them and 
clean up all your resources.  You will notice the View3D object is still 
hanging around in memory since the stage has reference to them.

To fix add this to the View3D constructor:

    addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);

and then add this function:

    private function onRemovedFromStage(event:Event):void
    {
        stage.removeEventListener(Event.RESIZE, onStageResized);
    }

This problem was found in the SVN tree pulled on 3/12/2010.

Original issue reported on code.google.com by mirsw...@gmail.com on 19 Mar 2010 at 8:37

GoogleCodeExporter commented 8 years ago

Original comment by katopz on 20 Mar 2010 at 3:01

GoogleCodeExporter commented 8 years ago
from now on, you can manually call view3D.destroy() for this
see 
http://away3d.googlecode.com/svn/branches/lite/libs/away3dlite/containers/View3D
.as

Original comment by katopz on 1 Apr 2010 at 12:16

GoogleCodeExporter commented 8 years ago
I got the exact problem and spent about 8 hours to trace it down. I finally got 
lucky
enough to see the problem and find a fix by doing below:

        private function onAddedToStage(event:Event):void
        {
            stage.addEventListener(Event.RESIZE, onStageResized, false, 0, true); // set
weakReference to true
        }

In fact, as a good practice, a lot of people including Adobe suggest to use weak
reference on addEventListener() call to prevent Memory Leak issue.

Original comment by vietson....@gmail.com on 30 Apr 2010 at 7:59

GoogleCodeExporter commented 8 years ago
actually it can't always use weak every where, especially in loader function or
variable in scope function it'll "too weak" for that and loader will randomly 
fail to
trigger complete event, mean gc is kill them before they complete

so that's why i'm set all weak ref as true, and will set as true case by case
if you confirm this case i'll change to true then

thank for report, i'll update this in branches
and if you find something else for gc, plz do tell me :)

Original comment by katopz on 30 Apr 2010 at 8:32

GoogleCodeExporter commented 8 years ago
You're so right that we don't always use weak reference but in most case 
especially
when you listen to Stage, parent containers, mouse events, ENTER_FRAME...

Yes, I confirm this case :)

Thanks for the wonderful Away3d. I love it.

Original comment by vietson....@gmail.com on 2 May 2010 at 1:00

GoogleCodeExporter commented 8 years ago
Seems Away3d normal has the same issue

Original comment by chris.de...@gmail.com on 15 Jun 2010 at 11:31