[Tkinter-discuss] tag_bind causes memory leak; fix?

dblank at brynmawr.edu dblank at brynmawr.edu
Sat Jun 10 23:50:54 CEST 2006


Tkinter users,

I have a Tkinter app that redraws objects on a canvas, about 10 times a
second. It doesn't reuse the drawn objects, it just draws and deletes.

In order to make it so that we can click on these objects, we have code like:

self.simulator.canvas.tag_bind("robot-%s" % self.name, "<B1-Motion>",
   func=lambda event,robot=self:self.mouse_event(event, "motion", robot))

for each object (a robot). First, is there a better way than doing this
after every object creation?

One problem with this method is that it appears to cause a memory leak.
Trying to unbind these, like:

self.simulator.canvas.unbind_all("<B1-Motion>")

or this method:

self.simulator.canvas.tag_unbind("robot-%s" % self.name, "<B1-Motion>")

doesn't seem to help. Any ideas on a better way, or how to stop the memory
leak?

Thanks!

-Doug



More information about the Tkinter-discuss mailing list