www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript Memory handling

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Posts
    2

    Javascript Memory handling

    Hi, check this out:
    Code:
    var y = function(){
    
    return "asdfg";
    
    }
    
    var z = function(){
    
          var x = new y();
          var div = document.createElement('div');
          div.innerHTML = x;
          document.body.appendChild(div);
          /*
                code goes on with hundreds of other functions and stuff,
                the entire application is build using only js, all the data comes trough sockets and the elements are created using js.
         */
    }
    as you see, inside 'z' there is 'x' and 'div', now suppose those two guys are only used there, no where else, so, in that case, do they still 'alive' inside the js on the web browser? do they vanish? do i need to set them to null to avoid any extra memory from being used on useless stuff?

    btw, this might be something idiot, but i wrote like 20k lines using js and all the elements are created using js, the applications stays up for like 8 hours until they close and it starts all over again on the other day. but for 8 hours, as it is a little big, i`m afraid i will get slow.

    thank you,
    sorry for the bad English,
    bb

  2. #2
    Join Date
    Mar 2011
    Posts
    1,133
    You don't need to worry about your JavaScript or your English.

    In terms of memory usage, each call to z() creates a temporary instance of the local var x, which is essentially discarded once the function has been run to completion. There are differences in how the various browsers handle this situation, but the result is pretty much the same. And browser developers have been putting an enormous amount of work into making them more efficient at memory handling as they work to make them faster. So the worst thing that might happen while your script is running is that it might stop running for a few moments while the JavaScript engine runs its "garbage collection" function. Afterwards, the script should continue to run normally. Good luck!
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jan 2013
    Posts
    2
    Thanks for your time rtrethewey,
    I was thinking something like you said, now i`m more confident.
    Mozilla Firefox 17 was using 900mb of ram memory after 4 or 5 hours running, but the new version uses only 500mb, still much, but way better than before.
    How do i mark this question as answered?
    Have a great day everyone,
    bb

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles