From d3b3fb08f19cc5c711f20ee9f335d62e52dd85da Mon Sep 17 00:00:00 2001 From: Peter Rekdal Sunde Date: Wed, 8 Jul 2015 13:05:08 +0200 Subject: [PATCH] Properly implement IDisposable. --- .../csharp/openalpr-net/openalpr-net.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bindings/csharp/openalpr-net/openalpr-net.cpp b/src/bindings/csharp/openalpr-net/openalpr-net.cpp index 17ea868..a5c8fb8 100644 --- a/src/bindings/csharp/openalpr-net/openalpr-net.cpp +++ b/src/bindings/csharp/openalpr-net/openalpr-net.cpp @@ -984,7 +984,7 @@ namespace openalprnet { bool m_cancel; }; - public ref class AlprNet sealed + public ref class AlprNet sealed : IDisposable { public: // Allocate the native object on the C++ Heap via a constructor @@ -993,11 +993,16 @@ namespace openalprnet { this->m_config = gcnew AlprConfigNet(this->m_Impl->getConfig()); } - // Deallocate the native object on a destructor - ~AlprNet(){ - delete m_Impl; - } + ~AlprNet() { + if(this->m_Disposed) + { + return; + } + this->!AlprNet(); + this->m_Disposed = true; + } + property AlprConfigNet^ Configuration { AlprConfigNet^ get() { @@ -1128,5 +1133,6 @@ namespace openalprnet { int m_topN; bool m_detectRegion; System::String^ m_defaultRegion; + bool m_Disposed; }; }