On Thu, 2008-02-07 at 11:19 +0200, Tero Saarni wrote:
> On Feb 7, 2008 10:04 AM, Tero Saarni <[EMAIL PROTECTED]> wrote:
> > Here's an another example.  It has Screen class based on clutter.Group
> > that contains just a label.  When pressing a key the old Screen is
> > faded out, removed from the stage and finally new Screen enters the
> > stage.  Old Screens never seem to get garbage collected.
> 
> Below is modified version with garbage collection working ok.  This
> one does not use clutter.effect_fade() helper function but instead
> creates clutter.BehaviourOpacity() which is stored in global variable.
>  That seems to prevent reference cycles.
> 
> However when implementing animation in Screen class itself and storing
> BehaviourOpacity as a member variable (instead of global variable;
> every widget of course needs to have it's own behaviour) I've caused
> an reference cycle again...
> 
> 

> current_screen = None
> counter = 1
> behaviour = None

> def on_key_press_event(a,b):
>     global behaviour
>     timeline = clutter.Timeline(duration=300)
>     alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
>     behaviour = clutter.BehaviourOpacity(alpha=alpha, opacity_start=255, 
> opacity_end=0)

again, you are recreating a behaviour all the time. I'm afraid this is
entirely python, as the underlying C library does not leak references
and the pyclutter bindings for behaviours are completely autogenerated.

if I update on_key_press_event() to this:

def on_key_press_event(a,b):
    global behaviour

    timeline = None

    if not behaviour:
        timeline = clutter.Timeline(duration=300)
        alpha = clutter.Alpha(timeline, clutter.ramp_inc_func)
        behaviour = clutter.BehaviourOpacity(alpha=alpha, opacity_start=255, 
opacity_end=0)
        behaviour.apply(current_screen)
        timeline.connect('completed', on_fade_out_completed)
    else:
        timeline = behaviour.get_alpha().get_timeline()

    assert(timeline != None)
    timeline.start()
    return True

I can't see any leakage.

ciao,
 Emmanuele.

-- 
Emmanuele Bassi, OpenedHand Ltd.
Unit R, Homesdale Business Centre
216-218 Homesdale Rd., Bromley - BR12QZ
http://www.o-hand.com

-- 
To unsubscribe send a mail to [EMAIL PROTECTED]

Reply via email to