I was reading the MSDN article about how to implement IDisposable and I am uncertain about the difference between managed and native resources cited in the article.
I have a class that must dispose 2 of its fields when it is disposed. Should I treat them as Managed (dispose only when disposing = true) or Native resources?
A managed resource is another managed type, which implements
IDisposable. You need to callDispose()on any otherIDisposabletype you use. Native resources are anything outside the managed world such as native Windows handles etc.EDIT: Answer to question in comment (too long for comment)
No that is just a managed type. A correctly constructed type, which doesn’t implement
IDisposablewill be handled by the garbage collector and you don’t have to do anything else. If your type uses a native resource directly (e.g. by calling Win32 libraries), you must implementIDisposableon your type and dispose of the resource(s) in theDisposemethod. If your type uses a native resource encapsulated by another type which implementsIDisposable, you must callDispose()on instances of this type in theDisposemethod of your type.