Types that own disposable fields should be disposable

This is a discussion on Types that own disposable fields should be disposable within the C# Programming forums, part of the General Programming Boards category; 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 ...

  1. #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

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 08-23-2008, 02:16 PM
  2. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 03:25 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM

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