Page MenuHomePhabricator

csharp: Refactor wrapper lifetime.
ClosedPublic

Authored by vitor.sousa on May 23 2019, 12:01 PM.

Details

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

Diff Detail

Repository
rEFL core/efl
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
vitor.sousa created this revision.May 23 2019, 12:01 PM
vitor.sousa requested review of this revision.May 23 2019, 12:01 PM
lauromoura accepted this revision.May 31 2019, 1:41 PM
This revision is now accepted and ready to land.May 31 2019, 1:41 PM
This revision was automatically updated to reflect the committed changes.