After doing more tests, I'm still getting a massive memory leak in
just destory and replacing 3DS models.
package
{
import away3d.animators.VertexAnimator;
import away3d.containers.View3D;
import away3d.core.base.Mesh;
import away3d.core.base.Vertex;
import away3d.core.utils.Debug;
import away3d.events.Loader3DEvent;
import away3d.events.MaterialEvent;
import away3d.loaders.data.AnimationData;
import away3d.loaders.data.MaterialData;
import away3d.loaders.Loader3D;
import away3d.loaders.LoaderCube;
import away3d.loaders.Max3DS;
import away3d.loaders.Md2;
import away3d.loaders.utils.AnimationLibrary;
import away3d.materials.BitmapFileMaterial;
import away3d.materials.BitmapMaterial;
import away3d.materials.WireColorMaterial;
import away3d.primitives.Plane;
import away3d.core.utils.Cast
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent
[SWF(backgroundColor = "#000000", width = "800", height = "600")]
public class MaxLoadTest extends Sprite
{
private var _view:View3D;
private var _md2:Max3DS
private var _loader:LoaderCube
private var _clickFlag:Boolean = false
public function MaxLoadTest()
{
//Debug.active = true
_view = new View3D();
addChild(_view);
_view.x = 400;
_view.y = 300;
_md2 = new Max3DS();
this.stage.addEventListener(MouseEvent.CLICK,
_onMouseClick);
}
private function _onMouseClick(e:Event):void
{
if (_clickFlag) {
cleanUp();
} else {
setUp();
}
}
private function cleanUp():void
{
trace("cleanUp")
removeEventListener(Event.ENTER_FRAME, _onEnterFrame);
for each (var materialData:MaterialData in
_loader.materialLibrary)
{
if (materialData.materialType ==
"textureMaterial")
{
(materialData.material as
BitmapMaterial).bitmap.dispose()
}
materialData.material = null
}
_loader.geometry = null
_view.scene.removeChild(_loader);
_loader = null
_clickFlag = false
}
private function setUp():void
{
trace("setUp")
_loader = new LoaderCube();
_view.scene.addChild(_loader);
_loader.addEventListener(Loader3DEvent.LOAD_SUCCESS,
_onLoaderSuccess)
_loader.loadGeometry("assets/room/room_d.3ds", _md2);
_clickFlag = true
}
private function _onLoaderSuccess(e:Loader3DEvent):void
{
trace("_onLoaderSuccess")
_loader.removeEventListener(Loader3DEvent.LOAD_SUCCESS,
_onLoaderSuccess)
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
}
private function _onEnterFrame(e:Event):void
{
_view.render();
}
}
}
There seems to be alot of people having the same sort of problem...
I've spent 3 days on this already and I can't really afford to spend
any more trying to figure out where I am going wrong, as I pretty sure
it's a leak in Away3D.
Do you think if I made my Away3D section an external SWF it would
solve the memory leak?
On Jun 7, 4:26 pm, colouredfunk <[email protected]> wrote:
> hey, still getting the same problem... I'm only creating view/scene/
> camera once. clearing all objects that I create, remove listeners...
> but thememorykeeps on going up.... like you said Number3D is the
> main suspect as it is taking up most of thememoryas it never getting
> any smaller!!
>
> This must amemoryleakin Away3D no?
>
> On Jun 7, 1:16 pm, Jensa <[email protected]> wrote:
>
>
>
> > Yeah. Just keep an instance of the View (or engine if you will)
> > somewhere in your app and add it to stage when you need it. Not sure
> > of your app setup, but maybe reference it using a Singleton/Static
> > class var so it's easy to instantiate and push to stage from anywhere?
>
> > As your file showed, there is most probably somememoryleakin the
> > view but it shouldn't be a problem if you do it like this. I didn't
> > check it fully, but it looked like the objects declared on stage were
> > not properly unreferenced as it was Number3D, Vertices, UV and other
> > basic classes that kept increasing in instance count in the profiler.
> > I'll see if I can look closer at it.
>
> > J
>
> > On Jun 7, 1:30 pm, colouredfunk <[email protected]> wrote:
>
> > > 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 amemoryleakin 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
> > > >memoryleak. However - after creating some ten thousand planes, the
> > > >memoryusage 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 -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -