summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eo_mono/NativeModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono/eo_mono/NativeModule.cs')
-rw-r--r--src/bindings/mono/eo_mono/NativeModule.cs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/bindings/mono/eo_mono/NativeModule.cs b/src/bindings/mono/eo_mono/NativeModule.cs
index fd3b315..ad9cc60 100644
--- a/src/bindings/mono/eo_mono/NativeModule.cs
+++ b/src/bindings/mono/eo_mono/NativeModule.cs
@@ -22,6 +22,7 @@ namespace Efl.Eo
22public partial class NativeModule : IDisposable 22public partial class NativeModule : IDisposable
23{ 23{
24 private Lazy<IntPtr> module; 24 private Lazy<IntPtr> module;
25 private bool disposed = false;
25 26
26 ///<summary>Lazily tries to load the module with the given name.</summary> 27 ///<summary>Lazily tries to load the module with the given name.</summary>
27 ///<param name="libName">The name of the module to load.</param> 28 ///<param name="libName">The name of the module to load.</param>
@@ -43,12 +44,39 @@ public partial class NativeModule : IDisposable
43 } 44 }
44 } 45 }
45 46
46 ///<summary>Unload and released the handle to the wrapped module.</summary> 47 /// <summary>Finalizer to be called from the Garbage Collector.</summary>
48 ~NativeModule()
49 {
50 Dispose(false);
51 }
52
53 /// <summary>Unload and released the handle to the wrapped module.</summary>
47 public void Dispose() 54 public void Dispose()
48 { 55 {
49 UnloadLibrary(module.Value); 56 Dispose(true);
50 module = null; 57 GC.SuppressFinalize(this);
51 } 58 }
59
60 /// <summary>Unload and released the handle to the wrapped module.</summary>
61 protected virtual void Dispose(bool disposing)
62 {
63 if (disposed)
64 {
65 return;
66 }
67
68 if (disposing)
69 {
70 module = null;
71 }
72
73 if (module.IsValueCreated)
74 {
75 UnloadLibrary(module.Value);
76 }
77
78 disposed = true;
79 }
52} 80}
53 81
54} 82}