> You are using the latest release, right?

Yep.

> There were memory leaks in previous versions (as this.fame 
> was not being set
> to null) , I have not had this problem recently.
> 
> If so, please submit it as a bug, but also supply a little 
> test-code to
> replicate this problem, that we can put in the /tests 
> directory, if you can.
> 
> Your solution does seem logical though.

Just to make sure I haven't missed some trick, some test code
is appended. When you hit the inc button, the old label should
be deleted, but DynObject.all retains its ref.  Thus the ref'd
object count increases and the labels are not gc'd.

If you add the 'delete DynObject.all[this.id]' to DynObject.del(),
then the ref'd count is constant (as expected).

Although not much memory is leaking in the example, in our
real-world case, we can lose up to 400k per "panel".

I could have subclassed Label and then override specficRemove()
to do the delete after calling the superclass specificRemove(),
but that's rather heavy-handed :-)


<html><head><title>Untitled</title>
<script language="Javascript" src="../src/dynapi.js"></script>
<script language="Javascript">
<!--
        DynAPI.setLibraryPath('../src/lib/')
        DynAPI.include('dynapi.api.*')
        DynAPI.include('dynapi.gui.*')
        DynAPI.include('dynapi.event.*')
//-->
</script>
<script>
        var target ;

        DynAPI.onLoad = function() {

                var incButton = new Button() ;
                incButton.setText("Inc") ;
                incButton.setSize(30,20) ;
                incButton.moveTo(20, 100) ;
                DynAPI.document.addChild(incButton) ;

                var myListener = new EventListener( this );
                myListener.onmouseup = function( e )
                {
                        updateTarget() ;
                }
                incButton.addEventListener(myListener) ;

                target = new DynLayer() ;
                target.setSize(400,30) ;
                target.moveTo(100,100) ;
                DynAPI.document.addChild(target) ;

                updateTarget() ;
        }

        function updateTarget()
        {
                var total_len = DynObject.Count ;
                var obj_cnt = getObjCount(DynObject.all) ;

                var label = new Label() ;
                label.setText("DynObject.Count=" + total_len + ", ref'd
DynObjects=" + obj_cnt) ;
                label.setSize(400,30) ;
                label.moveTo(10,10) ;

                // remove old layer tree from our target
                // I'd expect them to be free'd after this,
                // as I haven't retained the object references....
                target.deleteAllChildren() ;

                // and add new label.
                target.addChild(label) ;
        }

        // near-enough the number of objects in our associative array
        function getObjCount(assoc)
        {
                var cnt = 0 ;
                for (var i in assoc)
                        cnt++ ;
                return cnt ;
        }

</script>
</head>
<body>
</body>
</html>

_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://www.mail-archive.com/[email protected]/

Reply via email to