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

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
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 = ...
    objConn.Open

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

    And was given a nickel for every time I wrote:

    objRS.Close
    Set objRS = Nothing

    objConn.Close
    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] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article