SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot Rexibit's Avatar
    Join Date
    Jul 2008
    Location
    United States
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dealing with JavaScript Memory Leaks in IE

    I have several JavaScripts being added to the Head tag via DOM in my main JavaScript. This is done by a function that I call at the end of my page, right before my closing body tag. I tried having it be called during the header's execution, but IE 6 errored and wouldn't load the page.

    I thought everything was fixed, and went happily on my way until a friend was checking the page and said that it errored while executing one of the pages and froze the browser. I tried as well and found that it was leaking memory.

    I have searched countless articles on the Internet, and would like to have some help from JavaScript experts.

    Here is the code in my main file that is loaded in the Header:

    Code:
    function loadobject(file){
    	if (file.indexOf(".js")!=-1){ //If object is a js file
    		fileref=document.createElement('script')
    		fileref.setAttribute("type","text/javascript");
    		fileref.setAttribute("src", file);
    	}
    	else if (file.indexOf(".css")!=-1){ //If object is a css file
    		fileref=document.createElement("link")
    		fileref.setAttribute("rel", "stylesheet");
    		fileref.setAttribute("type", "text/css");
    		fileref.setAttribute("href", file);
    	}
    	document.getElementsByTagName("head").item(0).appendChild(fileref)
    }
    
    function l()
    {
    loadobject("http://www.rexibit.com/files_for_inclusion/scripts/rounded_corners_lite.js");
    loadobject("http://www.rexibit.com/files_for_inclusion/scripts/home_round_border.js");
    loadobject("http://www.rexibit.com/files_for_inclusion/scripts/prototype.js");
    loadobject("http://www.rexibit.com/files_for_inclusion/scripts/scriptaculous.js?load=effects,builder.js");
    loadobject("http://www.rexibit.com/files_for_inclusion/scripts/lightbox.js");	
    }
    It doesn't cause the page to frieze all the time. So it must be a slow leak. I would appreciate any advice that you might have.
    Rexibit Web Services
    Don't just build it - CSS it

  2. #2
    SitePoint Zealot Rexibit's Avatar
    Join Date
    Jul 2008
    Location
    United States
    Posts
    178
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Upsie.
    Rexibit Web Services
    Don't just build it - CSS it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •