Click here to Skip to main content
16,016,134 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Should I implement IDisposable? Pin
Guffa27-May-08 21:19
Guffa27-May-08 21:19 
Scott Dorman wrote:
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.


But we are not talking about a situation where the containing object will live longer than the item. We are talking about the disposal of a collection, so the collection will not live longer than it's items.

Scott Dorman wrote:
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.


It may very well happening during the use of the collection, but it has nothing at all to do with the disposal of the collection.

Scott Dorman wrote:
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.


You are repeating yourself, but you are still not explaining yourself. The GC determines if references are reachable or not, and unreachable references are not keeping objects from being collected, regardless if they are in the LOH or not. So how would the GC be helped in any way by setting a reference that is going to be unreachable to null?

Scott Dorman wrote:
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.


Again, why do you think that the GC can not determine that a reference is unused by the fact that it's unreachable? How would code that uses up CPU time by doing something that is completely unnecessary help performance?

Scott Dorman wrote:
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.


It's clear what you mean, but not why you are saying it. I have already explained that setting the items in the collection to null is only a waste of time, as making the collection itself unreachable also makes all references that it contains unreachable. You are only talking about other situations where it is benificial to set references to null.

Despite everything, the person most likely to be fooling you next is yourself.

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 
QuestionService launching app with admin rights not working other than session 0 (XP) - C# Pin
xtnerb26-May-08 3:35
xtnerb26-May-08 3:35 

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.