On Feb 7, 2008 4:26 PM, Emmanuele Bassi <[EMAIL PROTECTED]> wrote:
> On Thu, 2008-02-07 at 11:19 +0200, Tero Saarni wrote:
> > 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...
>
> 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.
>
Sorry, I was not being clear with too many code snippets I've sent!
I believe that specific example was not leaking memory even before
your changes, python destructor was being called correctly. The point
with that example was that even if recreating behavior all the time
the object inheriting from clutter.Group was garbage collectible by
removing reference to it from the python side (i.e. writing tnew
object over the old one stored in the global variable). The problem
is that this is not always possible:
The example I sent before this one (the one with
clutter.effect_fade()) leaks memory and I have not found any way to
fix this in Python.
I send yet another example (sorry), this one too leaks memory:
It has a simple custom widget class that implements animated
clutter.Label. Every instance of this widget is independent so new
behaviour needs to be instantiated in the constructor and stored into
the object itself. This apparently causes non-garbage-collectible
cyclic dependency between behavior and the widget. Even if I try to
destroy the widget it is never freed. I have not found workaround for
this...
--
Tero
import clutter
import gc
import time
stage = None
my_label = None
class AnimatedLabel(clutter.Label):
def __init__(self):
print 'INIT %s' % self
super(AnimatedLabel, self).__init__()
timeline = clutter.Timeline(duration=1000)
timeline.set_loop(True)
alpha = clutter.Alpha(timeline, clutter.sine_func)
self.behaviour = clutter.BehaviourDepth(alpha=alpha,
depth_start=0, depth_end=200)
self.behaviour.apply(self)
timeline.start()
def __del__(self):
print 'DEL %s' % self
def on_key_press_event(a,b):
global my_label
stage.remove(my_label)
# would do anything to get rid of the old object ;)
del my_label
my_label = None
gc.collect()
my_label = AnimatedLabel()
my_label.set_text(time.ctime())
my_label.set_position(100,100)
stage.add(my_label)
my_label.show()
stage = clutter.stage_get_default()
stage.set_size(320,240)
stage.connect('key-press-event', on_key_press_event)
my_label = AnimatedLabel()
my_label.set_text(time.ctime())
my_label.set_position(100,100)
stage.add(my_label)
stage.show_all()
clutter.main()
--
To unsubscribe send a mail to [EMAIL PROTECTED]