Question about ClutterScript and object ref counts



I quickly poked about this on IRC, but I'm still unsure if this is the expected behaviour or if it's a bug.

Consider the following minimal JSON script:
---------------------------
[
    {
        "id" : "actor1",
        "name" : "actor1",
        "type" : "ClutterActor"
    },
    {
        "id" : "trans1",
        "type" : "ClutterPropertyTransition",
        "property-name" : "x",
        "animatable" : {
            "id" : "actor1",
            "type" : "ClutterActor"
        }
    }
]
---------------------------

If I was to load this script and then unref it, all objects would still live. The "trans1" transition apparently owns "actor1".

After a bit of reading, I realized that _clutter_script_construct_object() calls a g_object_ref_sink when building the objects. This means that all GInitiallyUnowned objects will get their floating ref sunk, but all other plain GObjects (like ClutterTransition) will get their refcount bumped up at 2.

In the previous scenario, this means:
- actor1 gets built and g_object_ref_sink (actor1 ref_count = 1)
- trans1 is built (trans1 ref_count = 1) and g_object_ref_sink (trans1 ref_count = 2)
- trans1 set_animatable() bumps the ref count of actor1 (actor1 ref_count = 2)
- g_object_unref(script) drops the ref count on both objects. They are both still at ref_count = 1.

So, it seems that normally all unowned objects would be destroyed (like ClutterActor), but in this specific case it would not because its ref count got bumped up by another "non-unowned" object.

Modifying _clutter_script_construct_object() to only sink floating references would allow for all objects to be properly destroyed when unref'ing the script (like in the previous case), but I'm still unsure this would be the way to go. Maybe it's just a odd effect of using ClutterTransitions in scripts, where one would keep a ref on the transition to keep the actor alive.

Any thoughts?

Thanks
--
Dominique Bureau (bjurr)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]