To read the article online, visit http://www.4GuysFromRolla.com/webtech/top10/int1.shtml

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


  • Article Information
    Article Title: ASP Tips: Explicitly Close and Destroy Object Instances!
    Article Author: Scott Mitchell
    Article URL: http://www.4GuysFromRolla.com/webtech/top10/int1.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers