Skip to content

Disposing and destroying instances

Eduardo

Asked Feb 1, 2010, 1:16 AM EST1 answer
Share
LinkedInX
Hi all,

Do you know how to dispose instances?

examples:

Code
 clGeral Geral = new clGeral();
 DataTable dt = new DataTable();
 Geral.GetUsers(dt);

 Geral = Null;

clGeral is a class created by me, and there is no Dispose method inside because it is a simple class. It just opens SQL Connection, query and return some data, close SQL Connection.
Making Geral = null will solve my problem?  class will be destroyed or I need to do anything else?

Another exemple:
Code
 DataTable dt = new DataTable();
 ...
 ...
 ...
 dt.Dispose();
 dt = null;

In this case, DataTable have Dispose method, do I need to use dt = null after dt.Dispose ?  Or dt.Dispose is enought?

thanks!

1 Answer

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

  • 0
    Hi,

    In MSDN, assigning null is not recommended.If you want more efficient memory,you can try the following code:

    xxx = null;
    GC.Collect();
     
    0