disposing of objects

J

James Brett

Hi

I have an asp.net application and I've noticed that the aspnet_asp process
keeps creeping up in size which lead me to believe I was closing or
disposing of my object properly. When I create an instance of my object the
way I close them by setting it to nothing eg

Dim oUser as new User

oUser = nothing

Do I need to do anything else? Do I need to create a dispose method in my
class? if so how do I do that?

Cheers
James
 
C

Cor

Hi James,

Normaly when it are managed code objects you do not have to set them to
nothing, the garbage collector from the Net framework does that for you.

But as a good garbage collector he/she does that time by time and not one by
one.

I hope this helps?

Cor
 
G

Guest

James

Setting the objects to nothing will basically mark them for cleanup by the .NET Garbage Collector (GC). Memory used by the objects is not actually freed up until the GC has done it's job and removed them from memory. As Cor said, the GC cleans up at set time intervals and will clear anything from memory that has been marked for cleanup

You can actually force the GC to perform a cleanup when you want it to by calling "System.GC.Collect()" but I wouldn't recommend doing this unless absolutely necessary

Gary
 

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

Top