path: root/src/tests/efl_mono/Eo.cs
diff options
authorVitor Sousa <>2019-05-31 17:43:11 -0300
committerVitor Sousa <>2019-05-31 17:44:12 -0300
commitfcf5f1d2e2d9ce877d550dd3352bbd6e0527299e (patch)
tree419d1e22dddf6d9283ce05cd92817df1a6371fa9 /src/tests/efl_mono/Eo.cs
parent937da0b12c5b2b07a173199078856c35becdb0e0 (diff)
csharp: Refactor wrapper lifetime.
Summary: This commit makes use of the `ownership,shared` and `ownership,unique` events from Efl.Object in order to avoid the C# wrapper from being collected while C code holds a reference to the object. For example, creating a list of items in a for loop and attaching events to them would fails without this commit, as the C# GC may collect the wrapper. The basic idea is that we use a `WrapperSupervisor`, which is stored in the Eo data storage, with a GCHandle allocated for the lifetime of the underlying Eo object. This supervisor takes care of holding either a weak C# reference (when in unique mode, allowing the wrapper to be GC'd) or a hard C# reference (when in shared mode, making the wrapper non-collectable while the Eo has extra references). One limitation is that object graphs can leak if a shared object in the graph - an Eo child for example - stores a hard reference to another object in the graph as a C# field. In this example, this causes the parent to always have a hard C# reference (from the child) as the child is non-collectable due to the parent holding an Eo reference to it. Depends on D8678 Test Plan: `ninja test` and `make test` Reviewers: lauromoura, felipealmeida, woohyun, segfaultxavi Reviewed By: lauromoura Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision:
Diffstat (limited to 'src/tests/efl_mono/Eo.cs')
1 files changed, 15 insertions, 0 deletions
diff --git a/src/tests/efl_mono/Eo.cs b/src/tests/efl_mono/Eo.cs
index 95b6b6395e..be66f0842c 100644
--- a/src/tests/efl_mono/Eo.cs
+++ b/src/tests/efl_mono/Eo.cs
@@ -510,4 +510,19 @@ class TestProvider
510 } 510 }
511} 511}
512 512
513class TestObjectDeletion
515 public static void test_object_deletion()
516 {
517 var obj = new Dummy.PartHolder();
518 var part = obj.OnePart;
520 Test.AssertNotNull(part);
522 part.Del();
524 Test.AssertNull(obj.OnePart);
525 }
513} 528}