Comments Blog About Development Research Sites

JavaScript garbage collection in Google Chrome

Jun 27, 2010
One of the advantages of higher level programming languages is automatic garbage collection. Relatively modern languages like PHP, JAVA and C# can and will do this for you, meaning you do not need to worry about deallocating variables when you are done with them. As anyone who has ever spend a few hours finding a memory leak will tell you, this can be a blessing when done correctly.

Since GC routines are very good these days, new programmers are not always even aware of it - especially with short-lived scripts like those common in webpages, who cares? Of course, this changes when you start writing web services which do require decent memory management. Thus, it is a bit of a bother that JavaScript does not offer manual memory deallocation. There is a "delete" command, but it only removes variable references from objects. Some implementations offer manual GC triggering, but to my knowledge Chrome is not one of them.

Thus, when you are running a long-living webapplication, such as Project Holmgard is, the resulting memory usage might look something like this:



Interesting and just a tad bit annoying. The steady increase in memory usage is caused by a script that analyses the pixels of a unit's image and replaces a default colored pixel (red) with the color corresponding to the units owner. This means reading in an array of 1024 ~ 5184 bytes per unit roughly ten times a second. One might say some caching is in order ;)

FragFrog out!

New comment

Your name:
Comment: