[vlc-devel] commit: Cleanup IDisposable support ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat Feb 21 19:29:47 CET 2009


vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Feb 21 20:29:18 2009 +0200| [8416c5ff45d9c99ecd53e1d088bece8808cb6bb4] | committer: Rémi Denis-Courmont 

Cleanup IDisposable support

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8416c5ff45d9c99ecd53e1d088bece8808cb6bb4
---

 bindings/cil/src/exception.cs |   17 +++++++++++------
 bindings/cil/src/marshal.cs   |   16 ++++++++++++++--
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/bindings/cil/src/exception.cs b/bindings/cil/src/exception.cs
index 2b3118f..b8b3a88 100644
--- a/bindings/cil/src/exception.cs
+++ b/bindings/cil/src/exception.cs
@@ -105,12 +105,6 @@ namespace VideoLAN.LibVLC
         private static extern void Init (NativeException e);
         [DllImport ("libvlc.dll", EntryPoint="libvlc_exception_clear")]
         private static extern void Clear (NativeException e);
-        /*[DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_exception_raised")]
-        private static extern int Raised (NativeException e);*/
-        [DllImport ("libvlc.dll",
-                    EntryPoint="libvlc_exception_get_message")]
-        private static extern IntPtr GetMessage (NativeException e);
 
         public NativeException ()
         {
@@ -143,6 +137,17 @@ namespace VideoLAN.LibVLC
         /** IDisposable implementation. */
         public void Dispose ()
         {
+            Dispose (true);
+            GC.SuppressFinalize (this);
+        }
+
+        ~NativeException ()
+        {
+            Dispose (false);
+        }
+
+        private void Dispose (bool disposing)
+        {
             Clear (this);
         }
     };
diff --git a/bindings/cil/src/marshal.cs b/bindings/cil/src/marshal.cs
index 9d37394..2135aca 100644
--- a/bindings/cil/src/marshal.cs
+++ b/bindings/cil/src/marshal.cs
@@ -97,8 +97,20 @@ namespace VideoLAN.LibVLC
          */
         public void Dispose ()
         {
-            ex.Dispose ();
-            handle.Close ();
+            Dispose (true);
+            GC.SuppressFinalize (this);
+        }
+
+        protected virtual void Dispose (bool disposing)
+        {
+            if (disposing)
+            {
+                ex.Dispose ();
+                if (handle != null)
+                    handle.Close ();
+            }
+            ex = null;
+            handle = null;
         }
     };
 };




More information about the vlc-devel mailing list