|
View:
New views
10 Messages
—
Rating Filter:
Alert me
|
|
|
Object deletion and Memory IssueHello Everyone,
i have run across a problem regarding to the fact that i can't delete objects in Papervision3d. i made a simple example that showcases the problem. it simply creates 10 cube objects every 10 seconds. if there are already some cubes created, it tries to delete them. as you can see on the memory monitor the objects still remain in memory. http://www.perfectscript.de/memoryleaking/index.html i have included the code. sources.zip |
|
|
TriangleMesh3D does not cleanly dispose - Memory leakingHello,
after further study of the code i was able to isolate the cause of the issue. The problem lies somewhere in the instanciation of the TriangleMesh3D Class. if you try the following example you will notice the application will constantly need more and more memory. if you comment the blocks in function addCube and decomment the respected line to change TriangleMesh3D into Vertices3D everything works like expected. package memoryTest { import com.tPS.utils.FPSMemCounter; import flash.events.Event; import flash.events.TimerEvent; import flash.utils.Timer; import org.papervision3d.core.geom.TriangleMesh3D; import org.papervision3d.core.geom.Vertices3D; import org.papervision3d.view.BasicView; public class View extends BasicView { private var _cubes:Array; public function View() { super(); addChild( new MEMCounter() ); addEventListener( Event.ADDED_TO_STAGE, setup ); } private function setup( e:Event = null ) : void { _cubes = []; createCubes(); stage.addEventListener( Event.ENTER_FRAME, render ); var t:Timer = new Timer( 500 ); t.addEventListener( TimerEvent.TIMER, refreshCubes ); t.start(); } private function createCubes() : void { var i:int = -1; while( ++i < 1000 ) { addCube(); } } private function addCube() : void { //// MEMORY LOSS ////////////////////////////////////////////////////////////////////////// var c:TriangleMesh3D = new TriangleMesh3D( null, [], [] ); /////////////////////////////////////////////////////////////////////////////////////////////// /* * NO MEMORY LOSS */ //var c:Vertices3D = new Vertices3D( [] ); _cubes.push( c ); } private function refreshCubes( e:Event ) : void { var i:int = _cubes.length; while( --i > -1 ) { var c:Vertices3D = _cubes[i] as TriangleMesh3D; //scene.removeChild( c ); delete _cubes[i]; } _cubes.splice(0); _cubes = []; createCubes(); } private function render( e:Event = null ) : void { renderer.renderScene( scene, _camera, viewport, false ); } } } import flash.display.Sprite; import flash.text.TextField; import flash.events.Event; import flash.events.TimerEvent; import flash.utils.Timer; import flash.system.System; class MEMCounter extends Sprite{ private var _txt:TextField; public function MEMCounter() { addEventListener( Event.ADDED_TO_STAGE, setup ); } private function setup( e:Event ) : void { _txt = new TextField(); _txt.width = 120; addChild( _txt ); var t:Timer = new Timer( 1000 ); t.addEventListener( TimerEvent.TIMER, updateMem ); t.start(); } private function updateMem( e:TimerEvent ) : void { _txt.text = Number( System.totalMemory / 1024 / 1024 ).toFixed( 2 ) + 'Mb'; } }
|
|
|
Re: TriangleMesh3D does not cleanly dispose - Memory leakingHello,
It looks like the TriangleMesh3D class is cloning the display object and its geometry. Did you try to clean them manually? I'd suggest the addition of a clear() method to TriangleMesh3D..? Let me know, Denis On 19-Mar-08, at 4:31 AM, tPS wrote: > > Hello, > > after further study of the code i was able to isolate the cause of the > issue. > > The problem lies somewhere in the instanciation of the > TriangleMesh3D Class. > > if you try the following example you will notice the application will > constantly need more and more memory. if you comment the blocks in > function > addCube and decomment the respected line to change TriangleMesh3D into > Vertices3D everything works like expected. > > > > > package memoryTest > { > import com.tPS.utils.FPSMemCounter; > > import flash.events.Event; > import flash.events.TimerEvent; > import flash.utils.Timer; > > import org.papervision3d.core.geom.TriangleMesh3D; > import org.papervision3d.core.geom.Vertices3D; > import org.papervision3d.view.BasicView; > > > public class View extends BasicView > { > > private var _cubes:Array; > > public function View() > { > super(); > addChild( new MEMCounter() ); > addEventListener( Event.ADDED_TO_STAGE, setup ); > } > > > private function setup( e:Event = null ) : void { > > _cubes = []; > > createCubes(); > > stage.addEventListener( Event.ENTER_FRAME, render ); > var t:Timer = new Timer( 500 ); > t.addEventListener( TimerEvent.TIMER, refreshCubes ); > t.start(); > } > > > private function createCubes() : void { > var i:int = -1; > while( ++i < 1000 ) { > addCube(); > } > } > > > private function addCube() : void { > > //// MEMORY LOSS > ////////////////////////////////////////////////////////////////////////// > var c:TriangleMesh3D = new TriangleMesh3D( null, [], [] ); > > /////////////////////////////////////////////////////////////////////////////////////////////// > > /* > * NO MEMORY LOSS > */ > //var c:Vertices3D = new Vertices3D( [] ); > > > _cubes.push( c ); > } > > private function refreshCubes( e:Event ) : void { > var i:int = _cubes.length; > while( --i > -1 ) { > var c:Vertices3D = _cubes[i] as TriangleMesh3D; > //scene.removeChild( c ); > delete _cubes[i]; > } > _cubes.splice(0); > _cubes = []; > createCubes(); > } > > > > > private function render( e:Event = null ) : void { > renderer.renderScene( scene, _camera, viewport, false ); > } > > } > } > > > import flash.display.Sprite; > import flash.text.TextField; > import flash.events.Event; > import flash.events.TimerEvent; > import flash.utils.Timer; > import flash.system.System; > > class MEMCounter extends Sprite{ > > private var _txt:TextField; > > public function MEMCounter() { > addEventListener( Event.ADDED_TO_STAGE, setup ); > } > > private function setup( e:Event ) : void { > _txt = new TextField(); > _txt.width = 120; > addChild( _txt ); > > var t:Timer = new Timer( 1000 ); > t.addEventListener( TimerEvent.TIMER, updateMem ); > t.start(); > } > > > private function updateMem( e:TimerEvent ) : void { > _txt.text = Number( System.totalMemory / 1024 / > 1024 ).toFixed( 2 ) + > 'Mb'; > } > } > > > > > > > > tPS wrote: >> >> Hello Everyone, >> >> i have run across a problem regarding to the fact that i can't delete >> objects in Papervision3d. >> >> i made a simple example that showcases the problem. >> it simply creates 10 cube objects every 10 seconds. if there are >> already >> some cubes created, it tries to delete them. >> as you can see on the memory monitor the objects still remain in >> memory. >> >> http://www.perfectscript.de/memoryleaking/index.html >> >> i have included the code. >> http://www.nabble.com/file/p16098250/sources.zip sources.zip >> > > -- > View this message in context: http://www.nabble.com/Object-deletion-and-Memory-Issue-tp16098250p16143153.html > Sent from the Papervision3D mailing list archive at Nabble.com. > > > _______________________________________________ > Papervision3D mailing list > Papervision3D@... > http://osflash.org/mailman/listinfo/papervision3d_osflash.org _______________________________________________ Papervision3D mailing list Papervision3D@... http://osflash.org/mailman/listinfo/papervision3d_osflash.org |
|
|
Re: TriangleMesh3D does not cleanly dispose - Memory leakingstill now exactly it is my problem
![]() in my project i use different pv3d scenes and after loading and removing the scenes my memory grow up more and more. in remove functions i remove the listeners and all object references finally with null or delete but without any effect to memory. any solutions?
|
|
|
[SOLVED] TriangleMesh3D does not cleanly dispose - Memory leakingSo finally i worked through the code and found the solution.
the memory leaking is caused by the Materials registerObject function. the Material stores a reference to the DisplayObject3D's instance in a dictionary, so you manually have to unregister the object and then the object as well as the material are ready for the garbage collection. i would propose to add a dispose funciton to the DisplayObject3D Class /** * cleans up for deletion * * added by tPS */ public function dispose():void{ if(_material){ _material.unregisterObject(this); } } happy flashing
|
|
|
Re: [SOLVED] TriangleMesh3D does not cleanly dispose - Memory leakingThanks for pointing this out guys! I know Ralph had JUST pointed out an issue the other day and I want to say it was something around this, but I can't recall at this moment exactly - I'm sure he'll pop in and reply on this one
On Thu, Mar 20, 2008 at 6:01 AM, tPS <theperfectscript@...> wrote:
-- [ JPG ] _______________________________________________ Papervision3D mailing list Papervision3D@... http://osflash.org/mailman/listinfo/papervision3d_osflash.org |
|
|
Re: [SOLVED] TriangleMesh3D does not cleanly dispose - Memory leakingIf you have a dictionary storing references that is getting in the way of garbage collection just add the optional weakReference to the dictionary instantiation.
var myDict = new Dictionary(true); I actually went through and did this to my pv3d project, just as good housekeeping. I'll run a test later this morning to see if the issue described is fixed. On Thu, Mar 20, 2008 at 6:13 AM, John Grden <neoriley@...> wrote: Thanks for pointing this out guys! I know Ralph had JUST pointed out an issue the other day and I want to say it was something around this, but I can't recall at this moment exactly - I'm sure he'll pop in and reply on this one _______________________________________________ Papervision3D mailing list Papervision3D@... http://osflash.org/mailman/listinfo/papervision3d_osflash.org |
|
|
Re: Object deletion and Memory IssueHi there! Sorry it's taken a while to respond, I've been somewhat up against it this week! Thanks for taking the time to look into this, it certainly seems strange. I'll see if I can figure out what's going on over the next few days.
cheers! Seb On Tue, Mar 18, 2008 at 8:56 AM, tPS <theperfectscript@...> wrote:
_______________________________________________ Papervision3D mailing list Papervision3D@... http://osflash.org/mailman/listinfo/papervision3d_osflash.org |
|
|
Re: Object deletion and Memory Issuehey seb,
thanks for your quick response. i looked for dictionary in MaterialManager and MaterialObject3D and finally i added a new function in MaterialObject3D: public function dispose( do3d:DisplayObject3D ):void{ //unregister do3d from objects dictionary unregisterObject( do3d ); //unregister from materialmanager destroy(); //reset some attributes //maybe not necessary renderLayer = null; interactive = false; } i have build a little test. if you click on the first button ten spheres with listeners will create and store in an array. ----------------------- private function removeCreateClick(event : MouseEvent) : void { //array not empty, clear it clickRemove(); //create spheres for( var i : int = 0; i < 10; i ++){ var mat : ColorMaterial = new ColorMaterial( 0xff0000, .3 ); mat.interactive = true; mat.addEventListener( MouseEvent.CLICK, mousehandleClick ); mat.addEventListener( MouseEvent.MOUSE_OUT, mousehandleOut); mat.addEventListener( MouseEvent.MOUSE_OVER, mousehandleOver ); var obj : Sphere = new Sphere( mat, 100, 16, 12 ); obj.x = RandomNumber.generate(-1000, 1000); obj.y = RandomNumber.generate(-1000, 1000); obj.z = RandomNumber.generate(-1000, 1000); obj.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, handleClick ); obj.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleOut); obj.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleOver ); objectWrapper.addChild(obj); aObjects.push(obj); } } ----------------------- if the array not empty, the exist objects will delete befor: ---------------------- private function clickRemove( event : MouseEvent = null ) : void { for( var j : int = 0; j < aObjects.length; j++){ objectWrapper.removeChild( aObjects[j] as Sphere ); ( aObjects[j] as Sphere ).removeEventListener(InteractiveScene3DEvent.OBJECT_CLICK, handleClick ); ( aObjects[j] as Sphere ).removeEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleOut); ( aObjects[j] as Sphere ).removeEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleOver ); ( aObjects[j] as Sphere ).material.removeEventListener( MouseEvent.CLICK, mousehandleClick ); ( aObjects[j] as Sphere ).material.removeEventListener( MouseEvent.MOUSE_OUT, mousehandleOut); ( aObjects[j] as Sphere ).material.removeEventListener( MouseEvent.MOUSE_OVER, mousehandleOver ); // this is my magical line ;) ( ( aObjects[j] as Sphere ).material as MaterialObject3D ).dispose( aObjects[j] as DisplayObject3D ); aObjects[j] = null; } aObjects = new Array(); } --------------------- before: http://beta.mit.de/kwiegand/performancetest/memtest_Bad.html after: http://beta.mit.de/kwiegand/performancetest/memtest_allGood.html it seems working good. BUT.... ONE PROBLEM :( with bitmapassetmaterial und bitmapmaterial i have some issue. first dispose is ok, but the second use of the matial doesn't work. i get this error: ArgumentError: Error #2015: Ungültiges BitmapData. at flash.display::BitmapData/get width() at org.papervision3d.materials::BitmapMaterial/transformUV() at org.papervision3d.materials::BitmapMaterial/drawTriangle() at org.papervision3d.core.render.command::RenderTriangle/render() at org.papervision3d.render::BasicRenderEngine/org.papervision3d.render:BasicRenderEngine::doRender() at org.papervision3d.render::BasicRenderEngine/renderScene() at MemoryTest/renderLoop() any idea? regards kay |
|
|
Re: Object deletion and Memory Issuenow it works with bitmapfilemateials too.
i modified the bitmapfilematerial class. the destroy function detach now the file url from _loaderUrls dictionary, _subscribedMaterials object and _loadedBitmaps object. --- override protected function destroy():void { super.destroy(); bitmap.dispose(); // kill original url in dictionary delete _loaderUrls[url]; // unsubscribe material _subscribedMaterials[ url ] = null; // kill from loaded bitmap library _loadedBitmaps[ url ] = null; } --- hth kay
|
| Free embeddable forum powered by Nabble | Forum Help |