Closing Recordsets

J

James

Quick question about closing recordsets and connection objects. We're in
the process of rewriting a TON of bad code. None of it is even remotely
tabbed properly, it's impossible to read half the time and it never closes
connection objects or recordsets. Unfortunately, I've been assigned the
task of closing them. I assume I'm just doing:

recordset.close
Set recordset = Nothing

conn.close
Set conn = Nothing

....whenever it's no longer needed. I guess that my question is, how do I
need to handle redirects within a page. Should I close/set to nothing
before a redirect, or by the page losing "focus", will these objects be
released anyway?

Are there any general rules of thumb that might save me some time going
through the 1,000,000+ lines of code?

Thanks!
 
B

Bob Barrows [MVP]

James said:
Quick question about closing recordsets and connection objects.
We're in the process of rewriting a TON of bad code. None of it is
even remotely tabbed properly, it's impossible to read half the time
and it never closes connection objects or recordsets. Unfortunately,
I've been assigned the task of closing them. I assume I'm just doing:

recordset.close
Set recordset = Nothing

conn.close
Set conn = Nothing

...whenever it's no longer needed. I guess that my question is, how
do I need to handle redirects within a page. Should I close/set to
nothing before a redirect,

Yes. Any code that appears after a redirect will not be executed.
or by the page losing "focus", will these
objects be released anyway?

Maybe. It's the times that they don't close automatically that cause the
memory leaks
Are there any general rules of thumb that might save me some time
going through the 1,000,000+ lines of code?
Close and destroy child objects (recordsets, command objects) before closing
and destroying parent objects (connections). Note: command objects can't be
closed, only destroyed.

Or, the "Things I learned in kindergarten" version:
if you open it, close it
if you create it, destroy it

Sorry, there's nothing i've said here that will save you any time.

Bob Barrows
 
A

Aaron [SQL Server MVP]

Sorry, there's nothing i've said here that will save you any time.

Not necessarily true. Going through the code now and cleaning it up, while
boring and monotonous, will save time and gray hair later when trying to
find the source of a memory leak...

A
 
J

James

Fair enough. We've had an issue where maybe once few days, the site is
horribly slow and basically needs to be rebooted. I have the distinct
feeling that this might solve that problem, as we've been unable to track it
down anywhere else.
 
B

Bob Barrows [MVP]

Aaron said:
Not necessarily true. Going through the code now and cleaning it up,
while boring and monotonous, will save time and gray hair later when
trying to find the source of a memory leak...

A
:)
I meant clean-up time. Nothing I said provided any shortcuts to make this
task easier.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top