> call  dynlayer.delete...  methods to remove/delete it, no need in
> calling the "garbage" collection methods available..they are
> private/protected to DynAPI.

Hmm, I cannot find function called delete from neither dynlayer nor
dynobject. Did you mean function del() in dynobject, or am I missing
something here? I tried the del, but it doesn't seem to work (I'm using
version 2.54 w/ ie5.5 & NT4 sp6).

Perhaps the good old method of using an example helps here. I'll put a
commented listing here which has two ways to create and delete layers. The
other causes memory leakage and the other does not.

Cheers,
Tuomas


<html>
<head><title>DynAPI - Testing</title>
<!-- always begin by loading in the dynapi.js file -->
<script language="javascript"
src="/vx/common/dynapi/src/dynapi.js"></script>
<script language="javascript">
<!--
DynAPI.setLibraryPath("/vx/common/dynapi/src/lib/"); // set basepath URL of
DynAPI files
DynAPI.include("dynapi.api.*"); // include all dynapi/api/ files

// -->
</script>
<script language="Javascript">
/*
  This listing demonstrates the memory leakage if the object reference is
not removed
  form DynObject.all array. The button collect removes the reference and
leak does not.

  MakeLayer and DeleteLayer is taken from example found from:
  dynapi.sourceforge.net/snapshot/src/dynapi/examples/dynapi.api.delete.htm
*/
function MakeLayer(){
        var dlyr = new
DynLayer(null,Math.random()*400,Math.random()*400,50,50,'red');
        dlyr.setHTML("dynlayer");
        DynAPI.document.addChild(dlyr);
}
function DeleteLayer(){
        if (DynAPI.document.children.length>0) {

DynAPI.document.children[DynAPI.document.children.length-1].deleteFromParent
();
        }
}

//This is otherwise the same, but removes the reference from DynObject all
array.
function deleteAndCollect(){
        if (DynAPI.document.children.length>0) {
                var lyr = DynAPI.document.children[DynAPI.document.children.length-1];
                lyr.deleteFromParent();
                eval(lyr + "=null;"); //This is necessary for the carbage collection
        }
}

max = 1000;
//collect first creates layers and then removes them by DeleteLayer()
function leak(){
  for(var i=0; i<max; i++){
    MakeLayer();
  }
alert("created. Click ok to delete");
  for(var i=0; i<max; i++){
    DeleteLayer();
  }
}
//collect first creates layers and then removes them by deleteAndCollect()
function collect(){
  for(var i=0; i<max; i++){
    MakeLayer();
  }
alert("created. Click ok to delete");
  for(var i=0; i<max; i++){
    deleteAndCollect();
  }
}

</script>

</head>
<body>
<h1>Monitor the memory</h1>
<form>
<input type=button value=collect onclick=collect();>
<input type=button value=leak onclick=leak();>
</form>
</body>
</html>


_______________________________________________
Dynapi-Help mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-help

Reply via email to