Template recycling: how do I know what is managed and unmanaged?

Reading about the Dispose pattern , I see that the documentation repeatedly refers to "flushing managed and unmanaged code." And in the canonical implementation of the Dispose method, I see specific threads (depending on whether disposing true or false), designed to clear managed objects from unmanaged objects.

But I, a discreet novice, know which types are controlled and which are uncontrollable?

+6
dispose unmanaged
source share
5 answers

Short version: everything that also implements IDisposable needs to be called in your Dispose method. FxCop will also tell you if you missed something (or don't use IDisposable at all when you should be).

+3
source share

Unmanaged means native Win32 objects, mainly handles; and links to raw COM objects. These are resources that are not under the control (or control) of the .NET CLR.

+5
source share

Managed or unmanaged is not a big deal. If the class implements the IDisposable interface, you must call Dispose () when you are done with the object. Alternatively (preferably) use the operator to automatically call Dispose () when an object falls out of scope.

@Rob:
The answer is still the same. If your class manages any internal objects that implement IDisposable, it must also implement IDisposable. In the Dispose () method, call Dispose on these objects.

+2
source share

If you do not know, the types that you use will probably be available to you.

Unmanaged types refer to types that are unsafe, that is, do not meet the CLR security requirements.

Excellent definition :

Update

I do not understand the downward view? The question was specifically how to distinguish between managed and unmanaged types?

All other answers related to the IDispose question, not the managed / unmanaged question !?

Update 2

Still no explanation for the second downvote ...

I agree, the IDisposable object should always be deleted, but this does not answer the question of managed and unmanaged.

0
source share

I just propose to destroy all resources after using them. Everything that usually depends on a system resource, such as sockets and thread resources, that you want to explicitly free. When in doubt, leave and dispose. In the long run, you get rid of many debugging issues. Usually, when you call code that is not written in .NET, you can assume that this is not "managed code."

0
source share

All Articles