Don't you guys use Object Pooling? In general in Flash/AS3 coding if someone is facing a performance problem and you see little else but a for loop in an enterframe it is something to check especially if you see the keyword new twice in that loop as in your code. Because there are times where if the number of objects is stable as in your case then creating them once and reusing them is preferable to creating/destroying them over an over which can be an expensive operation in Flash and some other languages too. Object Pooling is included in many AS3 frameworks like Hype for example http://www.hypeframework.org/02_examples/objectpool/content/01_objectpool/ or you can write your own implementation. It might be that your problem is elsewhere or is away3d specific but that is the first general AS3 thing that I noticed from a quick look at your test code.
~dehash On 6/16/11, Flyon <[email protected]> wrote: > Here, a test file... Why would this cause memory to build up? > > package > { > import away3d.containers.View3D; > import away3d.materials.ColorMaterial; > import away3d.primitives.Sphere; > import flash.display.Sprite; > import flash.events.Event; > > [SWF(width="1280", height="1024", backgroundColor="#000000", > frameRate="30")] > public class Test extends Sprite > { > public var view:View3D; > > public function Test():void > { > view = new View3D(); > this.addChild(view); > this.addEventListener(Event.ENTER_FRAME, > _handleEnterFrame); > } > > private function _handleEnterFrame(e:Event):void > { > for (var i:Number = 0; i < 200; i++) > { > var x:Sphere = new Sphere(new > ColorMaterial(0x00ff00)); > view.scene.addChild(x); > view.scene.removeChild(x); > } > } > } > } > > > On 16 jun, 18:07, Flyon <[email protected]> wrote: >> I'm having about 10 objects adding a child object to themselves about >> 30 times per second. >> These child objects remain for about 2 secconds, after which they are >> removed (including all their references). >> >> This makes that about 300 objects are created and removed per seccond, >> and there are about 600 active objects at any time. >> >> After commenting more and more code I found this: >> >> When the child objects that are created are empty classes that extend >> the ObjectContainer3D class, the memory is stable. >> When I add one line of code to this child class so that they add a >> sphere to themselves, the memory increases slowsy... but keeps >> increasing!! >> When I add a PathExtrude instead of the sphere with about 100 points >> in them, memory goes through the roof. >> >> I don't understand why it keeps increasing with this one line of code? >> >> addChild(new Sphere(new ColorMaterial(0x00ff00, 1), 10)); >> >> After all, number of objects is stable, and memory stable without this >> line shows that the garbage collector does take care of all the >> removed objects right? >> >> I'm running this on the latest Broomstick from the svn.
