Skip to content

Disposing objects

pranahetha

Asked May 29, 2006, 1:04 AM EDT2 answers
Share
LinkedInX

Hi,

Iam working on an application where objects are more often have to be dynamically created!!!

How can i dispose the following objects completely from memory?

a form object
class object
dataset object
strings etc 

By assigning null only its reference is lost and not the object?

Can anyone tell me the correct way of disposing these objects?

Also is it proper to use Dispose method for all objects?

Hoping for a better answer!!!

Thanks

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0
    Unless, you have created complex objects (classes) of your own, there is no need to destroy object manually. They should all be destroyed by CLR automatically.

    Using Dispose is not recommended unless you have some resources such as GDI+ that must be disposed.
    0
  • 0
    If your worried about the amount of memory usage reported by Task Manager you should read this article: http://www.itwriting.com/dotnetmem.php

    As previously mentioned the Garbage Collection of the CLR does a good job for you.

    Edit: By assigning null, the Object is no longer referenced and then the Garbage Collection eats up the Object and will free the memory. Cant hurt to assign null to Objects you no longer require.
    0