Fog Creek Software
Discussion Board

ASP/VBScript Question

Are objects, declared and instantiated on an asp page,  implicitly destroyed when the server finishes building the page or do I have to explicitly set them to nothing to tell the garbage collector that there are no more references to that object?

For example, I declare and instantiate a connection and recordset object at the begining of the page.  I then traverse the recordset in the middle of the page.  At the end of the page, after the server is done parsing the file, are those objects 'stuck' in memory because there's still a reference to them?

Anon again
Saturday, March 15, 2003

They are automatically "cleaned" up. Basically you don't have to worry about it anymore. But best practices dictates that you try to free them up. Because this clean up is supposely not perfect. With regards to database connections though. ADO and IIS cooperate to keep some of these connections open for a few moments more until inactivity (no more accesses on any asp pages) times out the connection. This is because establishing a connection is a heavy weight operation and results in unpleasant pauses to the user access experience. You'll have to look up some ASP books to figure out how exactly IIS and ADO do this. Would someone please correct me if I am wrong?

Li-fan Chen
Saturday, March 15, 2003

In theory they are cleaned up.
In practice however, if you don't close and set to "nothing" all of your database and connections you will find your server stops responding every few days and will need a reboot.

Saturday, March 15, 2003

Some hosts get upset if you don't clean up your objects after yourself. If you're developing stuff that others may host/use elsewhere it pays to be tidy with your objects if only to keep them out of trouble.

Sunday, March 16, 2003

*  Recent Topics

*  Fog Creek Home