Page MenuHomePhabricator

efl-mono: Object gets deleted after a while even though it has an EFL parent
Closed, ResolvedPublic

Description

Consider the following program:

using System;

public class Program
{
        public static void Main()
        {
            efl.All.Init(efl.Components.Ui);

            var mainloop = efl.App.GetLoopMain();
            mainloop.IdleEvt += (object sender, EventArgs e) => {};

            new efl.Loop_Timer(mainloop, (efl.ILoop_Timer etimer) => {
                etimer.SetInterval(0.1);
                etimer.TickEvt += (object sender, EventArgs e) => {
                        Console.WriteLine("Tick");
                };
            });
            mainloop.Begin();
            efl.All.Shutdown();
        }
}

It creates a timer which prints "Tick" on the screen 10 times per second. It also registers to the Idle event, but does nothing.

If you run this, you should see that after a second (about 10 ticks), you get a long string of:

ERR<30856>:eo lib/eo/eo.c:1888 efl_unref() Eo ID 0x4000000073f4 is not a valid object. Current thread: 0x7f9c6947d700. This ID has probably been deleted or this was never a valid object ID. (domain=0, current_domain=2, local_domain=2, available_domains=[  1 2  ], generation=3f4, id=1c, ref=1)
ERR<30856>:mono /home/xartigas/repos/efl-bindings/src/lib/ecore/efl_loop_timer.eo.cs:170 on_TickEvt_NativeCallback() System.NullReferenceException: Object reference not set to an instance of an object
  at efl.Loop_Timer.On_TickEvt (System.EventArgs e) [0x00000] in <1e5730233a2c496fbc0261d31dcbc7de>:0 
  at efl.Loop_Timer.on_TickEvt_NativeCallback (System.IntPtr data, efl.Event& evt) [0x00006] in <1e5730233a2c496fbc0261d31dcbc7de>:0

If you store the timer in a variable: var timer = new efl.Loop_Timer(mainloop ... the problem goes away (You still get a warning about an unused variable).

It looks to me (C# noob) that the garbage collector is disposing of the timer object even though it is a children of the mainloop, so there is a live reference to it.

If you remove the event handler for the Idle event, the problem does not happen. Food for thought!

segfaultxavi triaged this task as TODO priority.
segfaultxavi updated the task description. (Show Details)Oct 1 2018, 6:54 AM
woohyun added a subscriber: lauromoura.
felipealmeida closed this task as Resolved.Jan 11 2019, 11:46 PM

This doesn't happen anymore. I've added a test case in my branch which will get pushed later.