Python 2.1.1 (#1, Aug 30 2001, 17:36:05)
[GCC 2.96 20000731 (Mandrake Linux 8.1 2.96-0.61mdk)] on linux-i386
Type "copyright", "credits" or "license" for more information.
>>> s=open("a big file").read()
>>> import Tkinter
>>> t=Tkinter.Tk()
>>> x=Tkinter.Text(t)
>>> x.pack()
>>> x.insert(end, s) # growing up memory to a little
more than size of s
>>> x.delete(1.0, end) # does not free memory
>>> x.insert(end, s) # memory goes up again
>>> x.delete(1.0, end) # memory freed by only one s
>>>
Is this a bug ? A problem with the version 1.152 of Tkinter ?
While the roughly-equivalent tcl script doesn't have quite the same memory
usage, you'll notice that no storage is freed after '.t delete 1.0 end'.
I suspect that this means some internal structure of the text widget
never shrinks when its contents shrink. Add to that the need to keep a
copy of the Python string converted to TCL, and the memory usage may be
"explained" as a combination of a Tkinter limitation and a Tk
limitation.
Jeff
proc ps {} {
puts [exec ps u [pid]]
}
text .t
pack .t
set s [string repeat "[string repeat x 72]\n" 40960]
ps ;# RSS 5520
.t insert end $s
ps ;# RSS 10240
.t delete 1.0 end
ps ;# RSS 10248
.t insert end $s
ps ;# RSS 10248
.t delete 1.0 end
ps ;# RSS 10248
.t insert end ""
ps ;# RSS 10248
Edward
--------------------------------------------------------------------
Edward K. Ream email: edr...@tds.net
Leo: Literate Editor with Outlines
Leo: http://personalpages.tds.net/~edream/front.html
--------------------------------------------------------------------
I know of one tkinter application that uses a lot of text widgets and leaks
hugely per Jeff Eppler's definition. I haven't figured out what the leak is,
but it's _quite_ noticable and I wish it wasn't there since I like the app a
lot. The app is Leo ( http://sourceforge.net/projects/leo/).
David LeBlanc
Seattle, WA USA
This wasn't intended as a jibe at Leo. The memory leakage really does bug
me, and I think it's a programming error, not an underlying attribute or
flaw.
As we've discussed before, Leo chews up large chunks of memory when outlines
are expanded/collapsed, and even when the same sections of the outline are
expanded/collapsed, the memory usage grows by significant amounts. I don't
see how this relates to undo since there's no change in the text.
BTW, I think that the text widget in Tk 8.4 does support undo, but I'm not
sure since I'm not active in the Tcl area much anymore.
David LeBlanc
Seattle, WA USA
> -----Original Message-----
> From: python-l...@python.org
> [mailto:python-l...@python.org]On Behalf Of Edward K. Ream
> Sent: Tuesday, November 26, 2002 13:52
> To: pytho...@python.org
> Subject: Re: memory leaks in Tkinter
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
Not to worry. I welcome bug reports. However, you have the best chance of
getting my attention by reporting them on Leo's SF site. I just stumbled on
this thread because I've been looking into leaks myself recently, and I have
been wondering how to separate "real" leaks from data associated with undo.
> As we've discussed before, Leo chews up large chunks of memory when
outlines
> are expanded/collapsed, and even when the same sections of the outline are
> expanded/collapsed, the memory usage grows by significant amounts. I don't
> see how this relates to undo since there's no change in the text.
I don't remember this as a bug report. Probably just my memory :-) Anyway,
it's now on Leo's bug list. I know Idle has a comment in its tree code
about leaking bindings, and Leo uses similar code. I'm not sure what can be
done about it; I've looked at this code several times and inspiration never
seems to strike.
Leo 3.9 uses only about 5% of the memory previously used for undoing text
operations. I was thinking that text undo was the only significant memory
hog; apparently I was wrong. Thanks again for the bug report.