C Board  

Go Back   C Board > General Programming Boards > C# Programming

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 06-16-2008, 11:56 PM   #1
Registered User
 
Join Date: May 2006
Posts: 1,579
Types that own disposable fields should be disposable

Hello everyone,


For this best practices rule,

http://msdn.microsoft.com/en-us/ms182172.aspx

What are the benefits of following this rule even if I am not wrapping an unmanaged resource, like FileStream in the sample in the page.

I think it is fine if the class does not implement IDisposable, since FileStream could be disposed (to release the native file handle) since it has its own Dispose method. Any ideas?


thanks in advance,
George
George2 is offline  
Old 06-17-2008, 03:58 AM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
It doesn't matter if the class you wrap has any handles internally. For all you know, the class you wrap needs to be disposed. If your class is disposed, the members of your class should be disposed, too. And if the class you wrap is disposable, you should not hide this with your wrapper class.
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline  
Closed Thread

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My Program gives a load of errors on comile, can some1 help explain them to me please MadnessRed C Programming 6 08-23-2008 01:16 PM
The Interactive Animation - my first released C program ulillillia General Discussions 48 05-10-2007 02:25 AM
Dikumud maxorator C++ Programming 1 10-01-2005 06:39 AM
i am not able to figure ot the starting point of this youngashish C++ Programming 7 10-07-2004 02:41 AM


All times are GMT -6. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22