Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The short answer would be anything that you go behind the CLR's back (to the OS) to obtain can be termed as '<strong>native</strong>'. </p> <ul> <li>unmanaged memory allocation. If you 'new' up a chunk of memory in a managed class CantStayManaged, then CantStayManaged is responsible for freeing this memory (resource).</li> <li>handles to files, pipes, events, synchronization constructs, etc. - as a thumb rule if you call WinAPIs to obtain pointers/handles to a resource, then those are 'native resources'</li> </ul> <p>So now CantStayManaged has 2 things it needs to cleanup before it bids adieu.</p> <ol> <li>Managed: Member fields and any resources the CLR allocated. This usually equates to calling Dispose on your 'Disposable' member objects.</li> <li>Unmanaged: all the sneaky low-level stuff we pull behind its back.</li> </ol> <p>There are 2 ways the object cleanup can be triggered now.</p> <ol> <li>Dispose(true) case: You called Dispose explicitly on your type. Good programmer.</li> <li>Dispose(false) case: You forgot to call Dispose, in which case the finalizer should kick in and still ensure proper cleanup.</li> </ol> <p>In both cases, the unmanaged resources should be freed up else 'LEAKS!', 'CRASHES!' et.all surface. But you should only attempt to cleanup managed resources only in Dispose() former case. In the latter/finalizer case - the CLR might have already finalized and collected some of your members, so you shouldn't access them (CLR doesn't guarantee an order in which an object graph is finalized.) Hence you avoid issues by guarding your managed cleanup with an <code>if (AmIBeingCalledFromDispose)</code> guard check</p> <p>HTH</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload