Cameron Hart wrote:
> 
> > Basically, all I've done is remove references in HTML-objects to dynapi
> > objects (including eventhandlers), as well as remove some circular
> > references within dynapi.
> 
> I'd be interested in seeing the code if you don't mind posting it.

Alright. Given that we'll soon have DynAPI X, this code will become
obsolete, but I needed something to work now with the current DynAPI. It
can surely be improved. In fact, I'm not even sure there's anything in
it which has any effect other than the "dlyr.elm.onxxx = null" when you
delete an element. Here are the changes:


Replacement for DynLayer.prototype.deleteElement:

DynLayer.deleteElement = function(dlyr) {
        DynLayer.flagDeleteChildren(dlyr);
        if (dlyr.elm) {
                if (is.ns4) {
                        dlyr.elm.visibility = "hide";
                        dlyr.elm.releaseEvents(Event.LOAD);

                       // Remove back-references from HTML-objects
                        for (var i in dlyr.doc.images) dlyr.doc.images[i].lyrobj = 
null;
                        for (i=0;i<dlyr.doc.links.length;i++) dlyr.doc.links[i].lyrobj 
=
null;
                        dlyr.doc.lyrobj = null;
                } else {
                        dlyr.elm.style.visibility = "hidden";
                        dlyr.elm.innerHTML = "";
                        dlyr.elm.outerHTML = "";
                        //Causes IE5 to crash
                        //if (is.ie5 && is.platform=="win32" && 
dlyr.elm.children.length>0)
dlyr.elm.removeNode(true);
                }

                // Remove back-references from HTML-objects
                dlyr.elm.lyrobj = dlyr.elm.onmousedown = dlyr.elm.onmouseup =
dlyr.elm.onmouseover = dlyr.elm.onmouseout = dlyr.elm.onclick =
dlyr.elm.ondblclick = dlyr.elm.oncontextmenu = null;
        }
        dlyr.elm = null;
        dlyr.doc = null;
        dlyr.css = null;
        dlyr.created = false;
};

New function DynLayer.prototype.destroy:

DynLayer.prototype.destroy = function() {
    while (this.children.length)
        this.children[this.children.length-1].destroy()

    this.deleteFromParent();

    // Remove circular references
    this.dyndoc=null;
    this.removeAllEventListeners();
};

New function DynDocument.prototype.destroy:

DynDocument.prototype.destroy = function() {
        while (this.children.length)
                this.children[this.children.length-1].destroy()
        
        // Remove back-references from HTML-objects
        this.dyndoc = this.elm.lyrobj = this.doc.lyrobj = this.elm.onresize =
this.elm.dyndoc = null;
        this.doc.onmousemove = this.doc.onmousedown = this.doc.onmouseup =
this.doc.onclick = this.doc.ondblclick = null;

        DynAPI.removeFromArray(DynDocument.dyndocs, this);
        delete DynDocument.dyndocsID[this.id];
}

New function DynAPI.destroy:

DynAPI.destroy = function() {
        while (DynDocument.dyndocs.length)
                DynDocument.dyndocs[DynDocument.dyndocs.length-1].destroy()
}


Then put DynAPI.destroy() in the onunload of your choice.


> > As soon as DynAPI X is stable and integrated with DynAPI 2, I'll want to
> > start using that for development and see what can be done about leaks
> > there.
> 
> How do people test for leaks? Just by seeing how much memory the browser is
> using?

Yes, exactly. If the browser just eats more and more and the memory
never goes down again, there's a leak. Given that IE garbage collects,
you'll have to refresh a few times to see if there's actually a leak or
if it's just that the memory hasn't been garbage collected. It's always
going to fluctuate up and down when you do things on the page.


Cheers,

Daniel

--
Daniel Aborg  <[EMAIL PROTECTED]> 
T: 0207 445 447  M: 07720 29 44 40

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

Reply via email to