Clean up issues

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

I have a simple application consisting of about 4 forms and a few db
connections...

I would like to make sure that I have done proper clean up when the user
exits the application.

For all connections I have included a...

cnn,Close()
cnn.Dispose()

Is there something similar that should be done wth Forms ? or variables
within a Sub routine ? or Command objects ? or Datasets ? or DataAdapters ?
Is there some standard code that can be used as a "clean-up catch-all" ?

Thanks !
 
Hello,

Most data objects have a Dispose method, and some have a close method. You
should call either of which is available, and then you should set the object
to nothing.

myObject = Nothing

But my advice is don't be paranoid about cleaning up. The GCC handles most
cleaning that you would need to do. Are there any problems that you are
facing with the garbage cleaning?

Cyril
 
Thanks for responding...

No, I have not faced any specific issues... just trying to tidy up things...

I hear somewhat contradictory things about the garbage cleaning... don't
understand what is necessary and what is not...
 
Couple more questions on this matter...

Since many of my varables have a scope of the "program's life" where is the
best place to put the clean-up code ? On Closed of the Main Form ? On
Closing of the Main Form ?

Also, is there an easy way to see what has been left open, or not disposed ?

Thanks !
 
Rob said:
Couple more questions on this matter...

Since many of my varables have a scope of the "program's life" where is
the best place to put the clean-up code ? On Closed of
the Main Form ? On Closing of the Main Form ?

What do you want to clean up? Variables are part of the process and don't
exist anymore after the app has been closed. There's nothing to clean up.
Also, is there an easy way to see what has been left open, or not disposed
?

No. If you write code to create new objects, also write the code to dispose
it, and everything is fine. For example, if I create and use a disposable
object locally, I dispose it locally, too. Something like

dim g as graphics

g = creategraphics

try
'code
finally
g.dispose
end try



Armin
 
Hi,

to answer your second question:

http://memprofiler.com/ is a very handy tool if you suspect you have a
memory leak on a form,project, it can show you which objects have or have
not been disposed and a lot more usefull information.

Hth

Greetz Peter
 

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

Back
Top