diff options
author | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-04 10:24:00 -0300 |
---|---|---|
committer | Lauro Moura <lauromoura@expertisesolutions.com.br> | 2019-12-04 10:30:38 -0300 |
commit | 3875c3d949694e5f5744912cfdc469b329f86747 (patch) | |
tree | bed4b5843dcf2ae20e9cfe61c6428401a4bde3ba | |
parent | 57a1b3a63e38ecb5065b141ac3c6b927aaed5746 (diff) |
csharp: WIP - Avoid string leaksdevs/lauromoura/remove_eina_mono-rebased
These dicts will tie the lifetime of the native strings to the lifetime
of the C# wrapper they are used with.
PS: What about strings in struct fields?
-rw-r--r-- | src/bindings/mono/eo_mono/EoWrapper.cs | 9 | ||||
-rw-r--r-- | src/bindings/mono/eo_mono/iwrapper.cs | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs index 554f4ec9bd..cc57be910c 100644 --- a/src/bindings/mono/eo_mono/EoWrapper.cs +++ b/src/bindings/mono/eo_mono/EoWrapper.cs | |||
@@ -19,6 +19,7 @@ using System.Runtime.CompilerServices; | |||
19 | using System.Threading; | 19 | using System.Threading; |
20 | using System.Reflection; | 20 | using System.Reflection; |
21 | using System.Collections; | 21 | using System.Collections; |
22 | using System.Collections.Concurrent; | ||
22 | 23 | ||
23 | namespace Efl | 24 | namespace Efl |
24 | { | 25 | { |
@@ -44,6 +45,9 @@ public abstract class EoWrapper : IWrapper, IDisposable | |||
44 | private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback); | 45 | private static Efl.EventCb ownershipUniqueDelegate = new Efl.EventCb(OwnershipUniqueCallback); |
45 | private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback); | 46 | private static Efl.EventCb ownershipSharedDelegate = new Efl.EventCb(OwnershipSharedCallback); |
46 | 47 | ||
48 | private ConcurrentDictionary<string, IntPtr> cached_strings = new ConcurrentDictionary<string, IntPtr>(); | ||
49 | private ConcurrentDictionary<string, IntPtr> cached_stringshares = new ConcurrentDictionary<string, IntPtr>(); | ||
50 | |||
47 | private Hashtable keyValueHash = null; | 51 | private Hashtable keyValueHash = null; |
48 | 52 | ||
49 | /// <summary>Constructor to be used when objects are expected to be constructed from native code. | 53 | /// <summary>Constructor to be used when objects are expected to be constructed from native code. |
@@ -195,9 +199,12 @@ public abstract class EoWrapper : IWrapper, IDisposable | |||
195 | { | 199 | { |
196 | Efl.Eo.Globals.efl_mono_thread_safe_native_dispose(handle); | 200 | Efl.Eo.Globals.efl_mono_thread_safe_native_dispose(handle); |
197 | } | 201 | } |
198 | |||
199 | Monitor.Exit(Efl.All.InitLock); | 202 | Monitor.Exit(Efl.All.InitLock); |
200 | } | 203 | } |
204 | |||
205 | // Are these threadsafe? | ||
206 | Efl.Eo.Globals.free_dict_values(cached_strings); | ||
207 | Efl.Eo.Globals.free_stringshare_values(cached_stringshares); | ||
201 | } | 208 | } |
202 | 209 | ||
203 | /// <summary>Turns the native pointer into a string representation. | 210 | /// <summary>Turns the native pointer into a string representation. |
diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index e5a357833f..d088b70a99 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs | |||
@@ -19,6 +19,7 @@ using System; | |||
19 | using System.Runtime.InteropServices; | 19 | using System.Runtime.InteropServices; |
20 | using System.Runtime.CompilerServices; | 20 | using System.Runtime.CompilerServices; |
21 | using System.Collections.Generic; | 21 | using System.Collections.Generic; |
22 | using System.Collections.Concurrent; | ||
22 | using System.Diagnostics; | 23 | using System.Diagnostics; |
23 | using System.Diagnostics.CodeAnalysis; | 24 | using System.Diagnostics.CodeAnalysis; |
24 | using System.Reflection; | 25 | using System.Reflection; |
@@ -528,7 +529,7 @@ public static class Globals | |||
528 | Efl.Eo.Globals.efl_mono_wrapper_supervisor_set(eo, GCHandle.ToIntPtr(gch)); | 529 | Efl.Eo.Globals.efl_mono_wrapper_supervisor_set(eo, GCHandle.ToIntPtr(gch)); |
529 | } | 530 | } |
530 | 531 | ||
531 | internal static void free_dict_values(Dictionary<String, IntPtr> dict) | 532 | internal static void free_dict_values(ConcurrentDictionary<String, IntPtr> dict) |
532 | { | 533 | { |
533 | foreach (IntPtr ptr in dict.Values) | 534 | foreach (IntPtr ptr in dict.Values) |
534 | { | 535 | { |
@@ -536,7 +537,7 @@ public static class Globals | |||
536 | } | 537 | } |
537 | } | 538 | } |
538 | 539 | ||
539 | internal static void free_stringshare_values(Dictionary<String, IntPtr> dict) | 540 | internal static void free_stringshare_values(ConcurrentDictionary<String, IntPtr> dict) |
540 | { | 541 | { |
541 | foreach (IntPtr ptr in dict.Values) | 542 | foreach (IntPtr ptr in dict.Values) |
542 | { | 543 | { |