Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you noted, in C++/CLI we implement ~ClassName and !ClassName, and the C++/CLI compiler writes Dispose(void) and Dispose(bool) for us.</p> <p>I tried deriving from HashAlgorithm, and I was able to get both the dispose &amp; finalize to work. Perhaps there's a subtle difference in how you have some of the methods declared.</p> <p>Here's my test code:</p> <pre><code>public ref class CppDispose : HashAlgorithm { private: ~CppDispose() { Debug::WriteLine("~CppDispose"); } !CppDispose() { Debug::WriteLine("!CppDispose"); } protected: virtual void HashCore(array&lt;Byte&gt;^ aray, int ibStart, int cbSize) override { } virtual array&lt;Byte&gt;^ HashFinal() override { return nullptr; } public: virtual void Initialize() override { } }; int main(array&lt;System::String ^&gt; ^args) { { CppDispose foo; Debug::WriteLine("Disposing: "); } { CppDispose^ foo = gcnew CppDispose(); Debug::WriteLine("Finalizing: "); foo = nullptr; GC::Collect(); } return 0; } </code></pre> <p>Output:</p> <pre> Disposing: ~CppDispose Finalizing: !CppDispose </pre> <p>So that you can see what's going on behind the scenes, here's the methods that the C++/CLI compiler wrote for us, decompiled to C# syntax. In this case, the parent class has Dispose(void) implemented, so it's not reimplemented here.</p> <pre><code>[HandleProcessCorruptedStateExceptions] protected override void Dispose([MarshalAs(UnmanagedType.U1)] bool flag1) { if (flag1) { try { this.~CppDispose(); } finally { base.Dispose(true); } } else { try { this.!CppDispose(); } finally { base.Dispose(false); } } } protected override void Finalize() { this.Dispose(false); } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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