ASP JavaScript: Garbage collection algorithm

Discussion in 'ASP General' started by Benjamin Johnston, Nov 30, 2005.

  1. 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
     
    Benjamin Johnston, Nov 30, 2005
    #1
    1. Advertising

  2. Benjamin Johnston wrote:
    > 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


    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], Dec 1, 2005
    #2
    1. Advertising


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

    /snip/
    > http://blogs.msdn.com/ericlippert/archive/2003/09/17/53038.aspx
    > http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx


    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
     
    Benjamin Johnston, Dec 2, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. IDoNothing

    Garbage Collection in ASP.NET

    IDoNothing, Jan 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    8,414
    cjohn
    Aug 20, 2009
  2. bruce barker

    Re: Garbage collection in ASP.NET

    bruce barker, Jan 9, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    418
    bruce barker
    Jan 9, 2004
  3. Dylan
    Replies:
    5
    Views:
    444
    Daniel T.
    Mar 22, 2005
  4. Replies:
    1
    Views:
    468
    mrstephengross
    Jul 25, 2005
  5. Øyvind Isaksen
    Replies:
    1
    Views:
    1,027
    Øyvind Isaksen
    May 18, 2007
Loading...

Share This Page