Setting ASP object variables to Nothing

Discussion in 'ASP General' started by mjkahn, May 30, 2005.

  1. mjkahn

    mjkahn Guest

    Folks,

    I have some ASP pages that contain code like this:

    dim foo
    set foo = Server.CreateObject("myDLL.myObject")
    foo.CallAMethod

    Is it important that I "set foo = Nothing" before each ASP page ends? If I
    don't set foo to nothing, will the memory it uses be freed automatically when
    the ASP page ends?

    Some information that might help:
    - IIS 5.0
    - Windows 2000 Server
    - myDLL is a custom Visual Basic 6 DLL (apartment threaded)

    Thanks very much!

    MJ.
     
    mjkahn, May 30, 2005
    #1
    1. Advertising

  2. mjkahn wrote:
    > Folks,
    >
    > I have some ASP pages that contain code like this:
    >
    > dim foo
    > set foo = Server.CreateObject("myDLL.myObject")
    > foo.CallAMethod
    >
    > Is it important that I "set foo = Nothing" before each ASP page ends?
    > If I don't set foo to nothing, will the memory it uses be freed
    > automatically when the ASP page ends?
    >


    The answer is a qualified "yes". As long as there is nothing preventing the
    object from being destroyed, then it will be automatically destroyed when
    the last reference to the object goes out of scope.

    http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx

    Bob Barrows
    --
    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], May 30, 2005
    #2
    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. Mark Kamoski

    setting to Nothing

    Mark Kamoski, Aug 7, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,084
    Robert Jacobson
    Aug 7, 2003
  2. Mark Rodrigues

    Re: Session variables set to nothing??

    Mark Rodrigues, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    387
    Mark Rodrigues
    Oct 29, 2003
  3. dotnettester

    Setting object = nothing after Response.end

    dotnettester, Sep 12, 2005, in forum: ASP General
    Replies:
    6
    Views:
    148
    Dave Anderson
    Sep 13, 2005
  4. Ven

    Setting object to Nothing

    Ven, Jan 6, 2006, in forum: ASP General
    Replies:
    2
    Views:
    102
    AnthonyWJones
    Jan 6, 2006
  5. Devin Jeanpierre
    Replies:
    2
    Views:
    465
    Devin Jeanpierre
    Feb 14, 2012
Loading...

Share This Page