ASP JavaScript: Garbage collection algorithm

B

Benjamin Johnston

Hi,

I've found lots of discussion about the JavaScript garbage collector,
but no clear answer to this question:

Is the garbage collection algorithm used in JavaScript on ASP based on
reference counting or tracing?


Thanks for your help,

(I'm planning on creating some user defined Objects with lots of cyclic
references (e.g., a.next.prev = a), and would like to know if this will
cause a problem for the garbage collector. The fact that garbage
collection in general isn't instantaneous suggests to me that it isn't
based on reference counting, but I just want to be sure.)

(I'm NOT using ASP.NET... just plain old ASP... if this is relevant)

-Benjamin Johnston
 
B

Bob Barrows [MVP]

Benjamin said:
Hi,

I've found lots of discussion about the JavaScript garbage collector,
but no clear answer to this question:

Is the garbage collection algorithm used in JavaScript on ASP based on
reference counting or tracing?
There's nothing better than Eric Lippert's blogs on this subject:
http://blogs.msdn.com/ericlippert/
Specifically:
http://blogs.msdn.com/ericlippert/archive/2003/09/17/53038.aspx
http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx
(I'm planning on creating some user defined Objects with lots of
cyclic references (e.g., a.next.prev = a), and would like to know if
this will cause a problem for the garbage collector.

Probably. Read what Eric has to say about closures.
http://blogs.msdn.com/ericlippert/archive/2003/09/17/53028.aspx
 
B

Benjamin Johnston


Fantastic, thanks a lot! This is exactly what I was looking for.


For the benefit of other readers and future readers searching the
archives, I'll summarize:

JavaScript in ASP uses a mark-and-sweep tracing garbage collector, so
it is okay to have cyclic **user-defined** data structures.

However, the garbage collector can't detect cycles involving
non-JavaScript objects (such as mixed VBScript and JavaScript, or
built-in objects, or COM objects); so such cycles will not be garbage
collected.

Also, it should be noted that this only applies to JavaScript, VBScript
uses a different garbage collector that doesn't handle cycles.

-Benjamin Johnston
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top