Thread: Types that own disposable fields should be disposable

  1. #1
    Registered User
    Join Date
    May 2006

    Types that own disposable fields should be disposable

    Hello everyone,

    For this best practices rule,

    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,

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

    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, 01:16 PM
  2. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06: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, 02:41 AM