Close those objects!

Read this tip to make your life smarter, better, faster and wiser. LifeTips is the place to go when you need to know about ASP and Web Development and other Web Development topics.

Do I need to do cleanup for instantiated objects?

Close those objects!

When you instantiate an obbect, such as a connection, recordset, filesystemobject, etc., remember to .close them, and to also set them to "nothing". Each time an object is created, memory is used up. Yes, when you exit a function the object instantiated within them go out of scope and supposedly are close, but it's a good programming practice to close and free up anyway.
For example:
dim rs
set rs = getUsersRS()
if not rs.eof then
do while not rs.eof

'do something here
rs.movenext
loop
end if
rs.close
if not rs is nothing then set rs = nothing

this effectively kills off the recordset object rs.

   

Comments

Nobody has commented on this tip yet. Be the first.



Name:


URL: (optional)


Comment:


Not finding the advice and tips you need on this Web Development Tip Site? Request a Tip Now!


Guru Spotlight
Mary White