When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Explicitly Close and Destroy Object Instances!

  • Back to Intermediate Developer's Tip Index
  • ASP Coding Tips Index...

    If I was charged a nickel for every time I wrote:

    Dim objConn, objRS
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionString = ...

    Set objRS = objConn.Execute("...")

    And was given a nickel for every time I wrote:

    Set objRS = Nothing

    Set objConn = Nothing

    I would be loosing money... a lot of money! :) In fact, I think the vast majority of ASP developers would be in the hole. While ASP should automatically close and free up all object instantiations, it is always a good idea to explicitly close and free up object references yourself. Another good reason to do this, is because when using connection pooling, you want to close and free your ADO objects as soon as possible, and if you do it explicitly once you're done with the ADO object, it dumps the connection back into the pool sooner than if you wait until the page terminates and let the terminating page implicitly close and free the ADO object.

    So, take my advice: if you ever do a Set someVar = ..., be sure you follow it up with a Set someVar = Nothing once you are through using someVar!

    Read a related article...

  • Back to Intermediate Developer's Tip Index
  • ASP Coding Tips Index...

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article