Click here to Skip to main content
15,914,386 members
Home / Discussions / C#
   

C#

 
GeneralRe: Should I implement IDisposable? Pin
Scott Dorman27-May-08 1:28
professionalScott Dorman27-May-08 1:28 
GeneralRe: Should I implement IDisposable? Pin
Guffa26-May-08 21:30
Guffa26-May-08 21:30 
GeneralRe: Should I implement IDisposable? Pin
Scott Dorman27-May-08 1:24
professionalScott Dorman27-May-08 1:24 
GeneralRe: Should I implement IDisposable? Pin
Guffa27-May-08 2:21
Guffa27-May-08 2:21 
GeneralRe: Should I implement IDisposable? Pin
DaveyM6927-May-08 11:53
professionalDaveyM6927-May-08 11:53 
GeneralRe: Should I implement IDisposable? Pin
Scott Dorman27-May-08 16:14
professionalScott Dorman27-May-08 16:14 
GeneralRe: Should I implement IDisposable? Pin
DaveyM6928-May-08 1:19
professionalDaveyM6928-May-08 1:19 
GeneralRe: Should I implement IDisposable? Pin
Scott Dorman27-May-08 16:03
professionalScott Dorman27-May-08 16:03 
Guffa wrote:
He's talking about setting references to null if you are going to keep the object that is containing the references. Does not apply.


Yes, he is talking about setting references to null if the containing object will potentially live longer than the item. In the case of a collection, this could be the case. Consider the act of removing a collection item...the item is no longer referenced but the containing collection is.

Guffa wrote:
He's talking about replacing a reference with a reference to a newly created object. Does not apply


This scenario is one of the more common causes for large amounts of memory consumption, and depending on what actions are taking place in the collection it very well may apply.

Guffa wrote:
He's talking about when the large objects heap is collected. Setting a reference to null doesn't change when that happens.


True. Setting the reference to null doesn't change when anything happens. However, the LOH doesn't get compacted like the other generations. Setting the reference to null does help the GC know that you are done using the reference.

Guffa wrote:
There is of course differences depending on where the object is allocated, but nothing that affects how the garbage collector finds out if the object is collectable or not.


Correct. The GC still has to walk to the heap to find objects that are no longer referenced. However, the LOH doesn't actually participate in the GC collection cycle. They are only removed if they are garbage.

Guffa wrote:
You said that setting the reference to null would help the garbage collector if the object is on the large objects heap. The only way that would be helpful would be if the garbage collector treats references to large objects differently, which is doesn't.


Again, the LOH isn't part of the normal GC generations and isn't compacted. Setting the reference to null when you know the object is no longer needed can yield performance gains.

Guffa wrote:
The discussion was about a collection of objects, so that's what I assumed that you were also talking about. If you are talking about something completely different, you will only be causing confusion if you don't specify what it is that you are talking about.


The discussion was about implementing IDisposable on a collection, to which my response was:
If any of the collection items implement IDisposable, then yes, you definately should implement IDisposable so your collection can call Dispose on the items.

If your items are large (greater than about 85,000 bytes) you should probably still implement IDisposable, but definately make sure you set the items to null.

I don't see how that could have been any clearer.

Scott.

—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

[Forum Guidelines] [Articles] [Blog]

GeneralRe: Should I implement IDisposable? Pin
Guffa27-May-08 21:19
Guffa27-May-08 21:19 
AnswerRe: Should I implement IDisposable? Pin
Guffa26-May-08 11:29
Guffa26-May-08 11:29 
GeneralRe: Should I implement IDisposable? Pin
DaveyM6927-May-08 1:19
professionalDaveyM6927-May-08 1:19 
QuestionPinned form Pin
netJP12L26-May-08 6:25
netJP12L26-May-08 6:25 
AnswerRe: Pinned form Pin
DaveyM6926-May-08 7:19
professionalDaveyM6926-May-08 7:19 
GeneralRe: Pinned form Pin
netJP12L26-May-08 8:56
netJP12L26-May-08 8:56 
GeneralRe: Pinned form Pin
DaveyM6926-May-08 9:09
professionalDaveyM6926-May-08 9:09 
QuestionSelect statement To display each row as colum for Gridview control Pin
Member 400849226-May-08 6:00
Member 400849226-May-08 6:00 
AnswerRe: Select statement To display each row as colum for Gridview control Pin
Ashfield26-May-08 8:09
Ashfield26-May-08 8:09 
AnswerRe: Select statement To display each row as colum for Gridview control Pin
Atif Ali Bhatti26-May-08 8:16
Atif Ali Bhatti26-May-08 8:16 
QuestionEnable custom control to be editable or intreactive in Design Mode Pin
leeoze26-May-08 3:46
leeoze26-May-08 3:46 
AnswerRe: Enable custom control to be editable or intreactive in Design Mode Pin
leppie26-May-08 4:08
leppie26-May-08 4:08 
GeneralRe: Enable custom control to be editable or intreactive in Design Mode Pin
Brady Kelly26-May-08 10:54
Brady Kelly26-May-08 10:54 
GeneralRe: Enable custom control to be editable or intreactive in Design Mode Pin
leppie26-May-08 12:12
leppie26-May-08 12:12 
GeneralRe: Enable custom control to be editable or intreactive in Design Mode Pin
Brady Kelly26-May-08 13:13
Brady Kelly26-May-08 13:13 
GeneralRe: Enable custom control to be editable or intreactive in Design Mode Pin
leppie26-May-08 23:33
leppie26-May-08 23:33 
GeneralRe: Enable custom control to be editable or intreactive in Design Mode Pin
Brady Kelly26-May-08 23:36
Brady Kelly26-May-08 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.