Friday, June 23, 2006

Javascript garbage collection in Internet Explorer

I'm dealing with a memory leak in a DHTML application, in IE.

Supposedly, there's an undocumented CollectGarbage function in JScript:

Q Can someone point me to some good documentation for garbage collection in JScript? I need to find out how JScript cleans up.

A JScript uses a mark-and-sweep garbage collector with a variety of heuristics used to determine when to run garbage collection. The JScript garbage collector works like this:

1. When the script engine is shut down, garbage is collected.
2. When 256 variants, or more than 64KB of strings, or more than 4096 array slots have been allocated, the garbage collector sets a flag that says collect soon.
3. Whenever a new statement is executed or the script debugger starts, that flag is checked, and if it is set, a collection is done.

There is an undocumented JScript function called CollectGarbage that forces a garbage collection. This is for testing purposes only...


This article is from May 2001, so I wonder if it still applies. I'm calling CollectGarbage in my Javascript; no error occurs but I can't tell if it's doing anything. Hm.

0 Comments:

Post a Comment

<< Home