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

C#

 
GeneralRe: Should I implement IDisposable? Pin
Scott Dorman26-May-08 15:00
professionalScott Dorman26-May-08 15:00 
GeneralRe: Should I implement IDisposable? Pin
S. Senthil Kumar26-May-08 20:57
S. Senthil Kumar26-May-08 20:57 
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 
DaveyM69 wrote:
I'm confused - not by you Scott or Guffa - but by the conflicting info around.
Results of 'Googling' have basically said if using unmanaged memory then it should be used, if not then there's no need - but it won't hurt.


Sorry...trying to make sure I'm as clear as possible. (The conflicting information is actually what prompted my article.)

The primary purpose for the GC is to manage memory, which is actually different than managing resources. The Dispose pattern is for managing resources. That being said, the simplest rules are:


  1. If you are using/managing/maintaining any unmanaged memory it should be considered mandatory to use the Dispose pattern.
  2. If you are using/managing/maintining any objects that implement IDisposable, it should be considered mandatory to use the Dispose pattern.
  3. Anything else, it should be evaluated on an "as-needed" basis based on the semantics of the object and how it is intended to be used.


DaveyM69 wrote:
If I'm getting the last point correctly - it doesn't matter how large the Collection object is, it's the objects (items) it holds? If any of them are large then there may be a case for implementing?


Yes, that's pretty much correct. Obviously, if the runtime allocates more than 85KB of memory to hold the actual collection object (the object itself, plus the pointers necessary for each of the "slots" in the collection) you should set it to null when you're done using the collection, but the collection itself isn't disposable per say. However, if any of the objects you maintain inside that collection implement IDisposable (or are larger than 85K themselves) you should implement IDisposable on the collection.

DaveyM69 wrote:
If so, the point that if any of the items implement Idisposable then the collection should too means that I should implement it on any potentialy large objects and collections that may hold them?


Yes, that's also correct...for largely the same reasons I mentioned above.

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
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 
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 

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.