efl/src/bindings/mono/eo_mono
Vitor Sousa fcf5f1d2e2 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: https://phab.enlightenment.org/D9014
2019-05-31 17:44:12 -03:00
..
EoWrapper.cs csharp: Refactor wrapper lifetime. 2019-05-31 17:44:12 -03:00
FunctionWrapper.cs mono: fix space and brace warnings of StyleCop 2019-04-02 16:57:52 +02:00
FunctionWrapper_Unix.cs mono: fix space and brace warnings of StyleCop 2019-04-02 16:57:52 +02:00
FunctionWrapper_Windows.cs mono: fix space and brace warnings of StyleCop 2019-04-02 16:57:52 +02:00
NativeModule.cs mono: fix space and brace warnings of StyleCop 2019-04-02 16:57:52 +02:00
NativeModule_Unix.cs mono: fix space and brace warnings of StyleCop 2019-04-02 16:57:52 +02:00
NativeModule_Windows.cs mono: fix space and brace warnings of StyleCop 2019-04-02 16:57:52 +02:00
WrapperSupervisor.cs csharp: Refactor wrapper lifetime. 2019-05-31 17:44:12 -03:00
iwrapper.cs csharp: Refactor wrapper lifetime. 2019-05-31 17:44:12 -03:00
meson.build csharp: Refactor wrapper lifetime. 2019-05-31 17:44:12 -03:00
workaround.cs csharp: Refactor wrapper lifetime. 2019-05-31 17:44:12 -03:00