Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should delete your unmanaged object from the <code>Dipose</code> method of your managed object. You should also call <code>Dispose</code> out of the <code>Finalize</code> method in case your code hasn't called <code>Dispose</code> before the garbage collector got to it. Adam Robinson's answer illustrates that much better.</p> <p>So if you are dilligent with you Dispose calls (and use <code>using</code> blocks) you shouldn't have shutdown crashes.</p> <p><strong>Edit:</strong> I think the problem is actually the unmanaged DLL getting unloaded before the finalizer runs. Ye old "Once the app is shutting down there are no guarantees as to what order the are unloaded".</p> <p>Perhaps you can experiment having your unmanaged resources in a managed C++ assembly? That way you know the DLL doesn't go bang before you are finished with it and you don't have to do ugly P/Invoke stuff.</p> <p>Here is an example from MSDN:</p> <pre><code>ref struct A { // destructor cleans up all resources ~A() { // clean up code to release managed resource // ... // to avoid code duplication // call finalizer to release unmanaged resources this-&gt;!A(); } // finalizer cleans up unmanaged resources // destructor or garbage collector will // clean up managed resources !A() { // clean up code to release unmanaged resource // ... } }; </code></pre> <p>More here <a href="http://msdn.microsoft.com/en-us/library/ms177197.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms177197.aspx</a></p> <p>The above is the same pattern as the C# one except you might get away with having the unamanaged resources in the managed C++ assembly. If you really MUST have those in an unmanaged DLL (not a static unmanaged library) then you are stuck, you will have the same shutdown issues.</p>
    singulars
    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. 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