Itemconfigure() and memory leak with tkinter Itemconfigure() and memory leak with tkinter tkinter tkinter

Itemconfigure() and memory leak with tkinter


If the problem is a memory leak in the tk core when allocating colors, then the only fix is to avoid doing the itemconfigure to change the color. One solution would be to create four rectangles for each position, one of each color. You can then modify the stacking order to have the color that you want on top, which will hide the other colors.

Clearly, this solution requires four times the number of canvas objects, but unless you're drawing hundreds of thousands, it shouldn't matter. The canvas can handle tens of thousands of objects fairly well.


I believe the problem is with the call to self.after. Every time you start the simulation a new infinite loop is created (which is never stopped). Indenting the line with self.afterso that it is within the if statement should resolve your issue, since then such a loop will be terminated when self.do_run becomes False.