.Close vs. Set = Nothing

Results 1 to 2 of 2

Thread: .Close vs. Set = Nothing

  1. #1
    Join Date
    Dec 1969

    Default .Close vs. Set = Nothing

    Do you have to explicitly close a recordset and set it to nothing to recollect the memory or will only setting it to nothing take care of it. In the example below do you NEED to have the last 2 lines, or is the last line enough by itself? I was told in the past that setting to nothing will take care of it but we are having resource problems. There are so many apps on the server that we can&#039;t determine which app is the root cause, but I know I am not always .close&#039;ing before setting to nothing. I do not want to have to change a ton of code if it will not help.<BR><BR>[code language="VBScript"]<BR>set RS = Server.CreateObject("ADODB.Recordset")<BR>...<BR>R S.open<BR>...<BR>RS.close &#039;Is this line neccessary?<BR>set RS = nothing<BR>[/code]

  2. #2
    Join Date
    Dec 1969

    Default You don't HAVE to do either...

    ...if this is the last (or nearly last) thing you do on an ASP page, then you can ignore it altogether. When the page finishes, all *WELL BEHAVED* COM objects will automatically be closed and the memory reclaimed.<BR><BR>Very early versions of some of the ADO objects were not "well behaved", but certainly ADO versions 2.5 and newer should all work just fine.<BR><BR>I&#039;d suggest that if you have resource problems it may not be due to ADO objects.<BR><BR>As for is the CLOSE done automatically when you do the SET to nothing... It should be, *IF* the variable you are setting is the last reference to the object (or only reference, of course). Remember: The VBS variable is only 16 bytes of memory; it is *NOT* the object, it&#039;s only a pointer to it. If you have multiple pointers/references to the same object, then the object can NOT be reclaimed until *ALL* pointers/references have been set to nothing.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts