Memory Woes

Scherer, Bill Bill.Scherer at verizonwireless.com
Wed Feb 26 13:27:36 EST 2003


On 26 Feb 2003, Greg wrote:

> I am using Python 2.2 to write a chart that plots realtime data
> similar to the one on the performance tab of the Windows task manager.
> 
> Here's the problem:  
>   I use a Tkinter canvas widget to display the data, and on each
> update (1/sec), the data and x gridlines scroll to the left.  If I
> don't delete any items from the canvas, the memory usage (as reported
> by the task manager) increases slowly.  

[P&M]

I had a similar chart with the same problem. I found no solution 
to the memory consumption with that method.  My charts are only 
updating once a minute, so what I do now is put my data into a 
list, and trim that as needed. The chart is then completely 
redrawn from the data in the list, every minute.

I suspect this method would flicker madly at 1Hz, but maybe it 
won't on your particular hardware???

Good luck!
- Bill

> This is understandable, since
> the canvas is still keeping track of the items that are no longer
> visible.  When I attempted to remedy this by deleting the items as
> they scroll off the chart, however, it began eating memory about 5
> times faster.
> 
> Here's the code I use to search and destroy items that are scrolling
> off the chart:
> 
>   # every item that scrolls along the x axis is given a "deleteMe"
>   # tag upon creation
>   for i in self.canvas.find_withtag("deleteMe"):
>     # margins[3] represents the left margin (the x coordinate of 
>     # the y axis)
>     if self.canvas.coords(i)[0] <= self.margins[3]:
>       self.canvas.delete(i)
> 
> I've read quite a few posts that suggest memory leaks with callback
> bindings in older versions of tk, but I don't have any bindings
> attached to any of the deleted items, and "deleteMe" is the only tag
> associated with any of them.
> 
> This script is meant to run over long periods of time, and the memory
> usage will become a major issue as time goes on.  Any thoughts as to
> why this is happening/how to fix it?  I'm fairly new to python and to
> gui programming, so feel free to let me know if I'm doing something
> completely idiotic.
> 
> Thanks, 
>   Greg
> 







More information about the Python-list mailing list