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. Advertisements

  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. Advertisements

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,196
    Robert Jacobson
    Aug 7, 2003
  2. Srinivasa Raghavan Sethuraman
    Replies:
    0
    Views:
    711
    Srinivasa Raghavan Sethuraman
    Jun 30, 2004
  3. Colin Graham

    DLL variables = nothing in debug mode

    Colin Graham, Mar 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    592
    Lucas Tam
    Mar 15, 2005
  4. wapsiii

    Date variables and nothing/null

    wapsiii, Oct 20, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    1,213
    wapsiii
    Oct 21, 2005
  5. Replies:
    9
    Views:
    1,316
  6. dotnettester

    Setting object = nothing after Response.end

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

    Setting object to Nothing

    Ven, Jan 6, 2006, in forum: ASP General
    Replies:
    2
    Views:
    211
    AnthonyWJones
    Jan 6, 2006
  8. Devin Jeanpierre
    Replies:
    2
    Views:
    759
    Devin Jeanpierre
    Feb 14, 2012
Loading...