On Feb 7, 2008 2:21 AM, Kashyap Ashwin <[EMAIL PROTECTED]> wrote:
> So for example, this one seems to work for me:
> ...

Thanks Ashwin!

Unfortunately it's not just the gst related objects that leak but e.g.
effects seem to cause some reference cycles too.

I of course agree with Emmanuele that Player object should be re-used.
 I used that as an example since the memory leak was so dramatic.  I
have implemented some simple widgets (sometimes animated with effects)
based on clutter.Group.   Re-using widget instances would complicate
the application logic a lot.  Consider that user can navigate back and
forth the UI.  It is not convenient to keep a pool of e.g. button
widgets that can be re-initialized and re-used later when the user
navigates back to the screen with the button.

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.

--
Tero


import clutter
import gc

current_screen = None
counter = 1
fade_effect_tmpl =
clutter.EffectTemplate(clutter.Timeline(duration=300),
clutter.ramp_inc_func)


class Screen(clutter.Group):

   def __init__(self, title_text):
       super(Screen, self).__init__()
       print 'INIT %s' % self
       title = clutter.Label()
       title.set_text(title_text)
       title.set_font_name('Arial 150px')
       title.set_color(clutter.Color(0,0,0))
       title.show()
       self.add(title)


   def __del__(self):
       print 'DEL %s' % self



def on_key_press_event(a,b):
    t = clutter.effect_fade(fade_effect_tmpl,
                            current_screen,
                            0,
                            on_fade_out_completed,
                            0)
    t.start()
    return True


def on_fade_out_completed(a,b):
    global current_screen
    global counter

    stage.remove(current_screen)

    # hopeless tries to get rid of 'current_screen' group
    del current_screen
    current_screen = None
    gc.collect()

    current_screen = Screen(str(counter))
    current_screen.set_position(120,30)
    stage.add(current_screen)
    current_screen.show()
    counter += 1

    return True



stage = clutter.stage_get_default()
stage.set_size(320,240)
stage.connect('key-press-event', on_key_press_event)

current_screen = Screen(str(counter))
current_screen.set_position(120,30)
stage.add(current_screen)
counter += 1

stage.show_all()
clutter.main()
-- 
To unsubscribe send a mail to [EMAIL PROTECTED]

Reply via email to