Hi thanks so much into looking into my problem. The reason why I had the view and scene created each time is because on the website I am creating it's a mixture of 3D and normal 2D sections... so on the other sections other than the Away3D I want to destroy everything, to keep everything nice and clean..
So are you saying I can't properly ever kill an Away3D section? If so, I guess there are two options; make the Away3D section an external SWF... or to leave the core engine in the background and not reinstantiate it each time the section loads... On Jun 7, 9:38 am, Jensa <[email protected]> wrote: > @colouredfunk You did not write what version of Away3D (Full/Lite, F9/ > F10) you were using, but based on your code I guessed it was the Flash > 9 branch. > > I've had a look at your file using the Flash Builder profiler and I > get the same results but this is not a memory leak in Away3D. Your > main problem here is that you add and remove the view all the time. > You should not need to do this ever. One view should be enough for any > object as you can change what scene it is rendering. > > In the example below, I've changed your code so that the view is only > created once and that on every second frame we make 500 planes and > render them so we see some faster results. On the next frame we remove > them. > > Pay close attention to your profiler as you run this code. Initially, > a lot of objects will accumulate and it will look like there is a > memory leak. However - after creating some ten thousand planes, the > memory usage flattens out. It's only at this point that the Garbage > Collection kicks in. > > J > > CODE: > > package > { > import away3d.containers.View3D; > import away3d.materials.WireColorMaterial; > import away3d.primitives.Plane; > > import flash.display.Sprite; > import flash.events.Event; > import flash.events.MouseEvent; > > [SWF(backgroundColor="#000000", width="800", height="600")] > public class Leak3 extends Sprite > { > private var _view:View3D; > private var _clickFlag:Boolean = false > private var numPlanesPerFrame:Number = 500; > private var planeArray:Array; > > public function Leak3() > { > planeArray = new Array(); > _view = new View3D(); > addChild(_view); > _view.x = 400; > _view.y = 300; > this.stage.addEventListener(Event.ENTER_FRAME, > _onMouseClick); > } > private function _onMouseClick(e:Event):void > { > if (_clickFlag) { > cleanUp(); > } else { > setUp(); > _onEnterFrame(e); > } > } > private function cleanUp():void > { > var plane:Plane; > while(planeArray.length > 0){ > plane = planeArray.pop() as Plane; > _view.scene.removeChild(plane); > } > _clickFlag = false; > > } > private function setUp():void > { > var i:int; var plane:Plane; > for(i = 0; i<numPlanesPerFrame;i++){ > _clickFlag = true; > plane = new Plane(); > plane.width = 80; > plane.height = 60; > plane.x = 800*Math.random()-400; > plane.y = 600*Math.random()-300; > plane.bothsides = true; > plane.material = new WireColorMaterial(); > _view.scene.addChild(plane); > planeArray.push( plane ); > } > } > private function _onEnterFrame(e:Event):void > { > _view.render(); > } > } > > > > }- Hide quoted text - > > - Show quoted text -
