SiteExperts.com Logo Home | Community | Developer's Paradise
User Groups | Site Tools | Site Information | Search
 Main Menu
 Forums
SiteExperts.com Forums
All Discussions

SiteExperts Feedback
The Lounge
Dynamic HTML
Site Design/ Critiques
HTML and CSS
XML Technologies
The Wireless Internet
Internet Explorer
Microsoft .NET
The Server
Technical Support

Sponsored Links

User Groups : Forums : SiteExperts : Microsoft .NET :

Previous DiscussionNext Discussion
 Dispose() vs null
Ok, I hope some of the folks who used to post on here still do, and I hope you see this. I know this site has been overrun with spam lately, so that you guys don't come here much, but I have a serious C# question.

Ok, let's say I create a class in C# called MyClass

Now, let's say in a code-behind, I reference it like this:

MyClass objMC = new MyClass();

And then I do whatever I need to do with it.

When I'm done, I want the GC to clean it up.

What's the difference in using something like

objMC.Dispose();

versus

objMC = null;

I understand that to use Dispose() I have to add some additional code (including a destructor, ~MyClass) to the class itself.

But what's the "behind the scenes" difference, and which one is better to use?

Started By Monte on Dec 12, 2008 at 12:57:53 PM

15 Response(s) | Reply

View All Replies | Goto Page: 3 2 1
Monte on Dec 15, 2008 at 11:02:12 AM

The first one helps a little, especially the discussion on Dispose(), which I think is page 3.

So, I guess my question would be, what's the difference in setting an object (Class) I create to null, versus using Dispose(), like this:

This:

objMyCreatedClass = null;

versus this:

objMyCreatedClass.Dispose();

But if I'm reading it correctly, Dispose() is designed to release resources (sockets, Database Connections, File handles).

Right?


View All Replies | Goto Page: 3 2 1

To respond to a discussion, you must first logon.

If you are not registered, please register yourself to become a member of the SiteExperts.community.

User Name
Password
Copyright 1997-2000 InsideDHTML.com, LLC. All rights reserved.