« Return to Thread: Object deletion and Memory Issue

Re: [SOLVED] TriangleMesh3D does not cleanly dispose - Memory leaking

by John Grden-2 :: Rate this Message:

Reply to Author | View in Thread

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

On Thu, Mar 20, 2008 at 6:01 AM, tPS <theperfectscript@...> wrote:

So 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



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-tp16098250p16176347.html
Sent from the Papervision3D mailing list archive at Nabble.com.


_______________________________________________
Papervision3D mailing list
Papervision3D@...
http://osflash.org/mailman/listinfo/papervision3d_osflash.org



--
[ JPG ]
_______________________________________________
Papervision3D mailing list
Papervision3D@...
http://osflash.org/mailman/listinfo/papervision3d_osflash.org

 « Return to Thread: Object deletion and Memory Issue