[thelist] checking for unclosed objects in ASP

David.Cantrell at Gunter.AF.mil David.Cantrell at Gunter.AF.mil
Wed Oct 2 10:09:01 CDT 2002

>that's what I was thinking of doing...  just hoping there was a more
>generic method that I could include in my debug fxn

Not really. As has been stated already, ASP does not really clean up after

While you still have to destroy your objects manually, here's a quick
shortcut that can make it a one-liner for each object:

Sub Destroy( obj )
	On Error Resume Next
	Set obj = Nothing
	On Error Goto 0
End Sub

This will take care of your ADO objects (or anything else requiring a close)
and destroy them. You can even pass it a string and it will happily set it
to Nothing for you, thanks to the error suppression.

Also, if you use VBScript classes, I tend to be in the habit of managing
internal objects as private properties and calling private method Destroy()
on each of them in the Class_Terminate() routine, so it cleans up after
itself when the class is destroyed.

The bonus to using VBScript classes that way, not sure if everybody is aware
of this, is that since it is simple VBScript it is automatically destroyed
by ASP when the page goes out of scope, and the Class_Terminate() is fired.
You don't have to Destroy() the class instance yourself, just make it and
forget about it. And Class_Terminate() makes cleanup very simple, provided
you design it in, of course. :)


More information about the thelist mailing list