473,473 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Memory leak in Tkinter?????

#When I'm running this script on my windows NT4.0 box,
#every time dialog box is reopened there is memory growth 384K.

#Bellow is the text I sent to Stephen Ferg (author of easygui)

# I have tested the pure Tkinter,
# by modifiing on of the examples in the distribution.
# This little guy also exibits the same behaviour.
# Namely: every time the window is closed and reoppend,
# there is memory leak of several hundreds 384K
# (good number??? 256 + 128??? or it's windows?)
# del root does not help at all.
# Anyway, I don't think that this leak is in easygui.
# The leak (if any is in TKinter (or it's windows implementation).
# I'm not runnin linux in my shop, so I will ask my friends to tes it on linux,
# will keep you posted.

from Tkinter import *
import string

# This program shows how to use a simple type-in box

class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()

self.entrythingy = Entry()
self.entrythingy.pack()

# and here we get a callback when the user hits return. we could
# make the key that triggers the callback anything we wanted to.
# other typical options might be <Key-Tab> or <Key> (for anything)
self.entrythingy.bind('<Key-Return>', self.print_contents)

def print_contents(self, event):
print "hi. contents of entry is now ---->", self.entrythingy.get()

while 1:
root = App()
root.master.title("Foo")
root.mainloop()
del root

#I found this memory leak while working with easygui.
#Initially I thought, that the leak is caused by the way easygui opens
#and closes the window/application.
#But plain Tkinter also has leaks. What is wrong?
#A friend of mine ran this script on his MAC and here is his reply:

##Yep, I'm seeing a .32 MB leak whenever I close the window and it
##reopens. Also seeing a high number of page faults for that process
##that increase when it is closed, so I think the memory for the window
##is not being deallocated, then Python hits an exception after it page
##faults trying to access it, and it then spawns a new one.
Jul 18 '05 #1
2 3618
el*******@hotmail.com (Elbert Lev) wrote in message news:<94**************************@posting.google. com>...
#When I'm running this script on my windows NT4.0 box,
#every time dialog box is reopened there is memory growth 384K.

#Bellow is the text I sent to Stephen Ferg (author of easygui)

# I have tested the pure Tkinter,
# by modifiing on of the examples in the distribution.
# This little guy also exibits the same behaviour.
# Namely: every time the window is closed and reoppend,
# there is memory leak of several hundreds 384K
# (good number??? 256 + 128??? or it's windows?)
# del root does not help at all.
# Anyway, I don't think that this leak is in easygui.
# The leak (if any is in TKinter (or it's windows implementation).
# I'm not runnin linux in my shop, so I will ask my friends to tes it on linux,
# will keep you posted.

I don't see a memory leak here on my linux box; there's a noticeable
increase of memory use if I close/reopen the window a few times within
a couple of seconds, but after about 5 seconds it disappears, so it
looks like python's garbage collection works properly (are you aware
that calling "del" does not free the memory immediately but just
remove the reference to the deleted object so it can be garbage
collected later on).
from Tkinter import *
import string

# This program shows how to use a simple type-in box
I'm not sure what you want to do with this program, looks rather like
a useless type-in box to me.

class App(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()

self.entrythingy = Entry()
self.entrythingy.pack()

# and here we get a callback when the user hits return. we could
# make the key that triggers the callback anything we wanted to.
# other typical options might be <Key-Tab> or <Key> (for anything)
self.entrythingy.bind('<Key-Return>', self.print_contents)

def print_contents(self, event):
print "hi. contents of entry is now ---->", self.entrythingy.get()

while 1:
root = App()
root.master.title("Foo")
root.mainloop()
del root

Why do you use the "while 1" condition to create your "dialog box"?
Notice that you create and endless loop without any "break" condition,
there's no way to stop the program from the gui itself which is
definitely no good idea.
Besides this you should be very careful using "while 1" statements in
any case.
For example try this:
def test(): .... l = []
.... while 1:
.... l.append(1)
.... test()


The result is of course not a python bug but a programmer's mistake.
#I found this memory leak while working with easygui.
#Initially I thought, that the leak is caused by the way easygui opens
#and closes the window/application.
#But plain Tkinter also has leaks. What is wrong?
I don't have windows or mac here, but on my linux box it looks like
the only thing that's wrong is the code.
#A friend of mine ran this script on his MAC and here is his reply:

##Yep, I'm seeing a .32 MB leak whenever I close the window and it
##reopens. Also seeing a high number of page faults for that process
##that increase when it is closed, so I think the memory for the window
##is not being deallocated, then Python hits an exception after it page
##faults trying to access it, and it then spawns a new one.


Michael
Jul 18 '05 #2
kl*******@web.de (klappnase) wrote in message news:<a7**************************@posting.google. com>...
el*******@hotmail.com (Elbert Lev) wrote in message news:<94**************************@posting.google. com>... I don't see a memory leak here on my linux box; there's a noticeable
increase of memory use if I close/reopen the window a few times within
a couple of seconds, but after about 5 seconds it disappears, so it
looks like python's garbage collection works properly (are you aware
that calling "del" does not free the memory immediately but just
remove the reference to the deleted object so it can be garbage
collected later on).
I don't think this is a correct statement. Python uses refference
counting. So, as soon as rc goes to 0, object is deleted. This can be
done several ways:

a = list(1,2,3)
del a # a is deleted

or

a = list(1,2,3)
a = 0 # list content is deleted and new object is created

See Language Reference 3.1 for more details.

Python isn't Java and DOES NOT HAVE lazy garbage collection (but you
can call it manualy. In this case ciclic references are counted and
resolved). I checked them and the number of items in gc.garbage was 0
Why do you use the "while 1" condition to create your "dialog box"?
Notice that you create and endless loop without any "break" condition,
there's no way to stop the program from the gui itself which is
definitely no good idea.
Besides this you should be very careful using "while 1" statements in
any case. .................. I don't have windows or mac here, but on my linux box it looks like
the only thing that's wrong is the code.


Sure while 1: is a test case, sure the program shows a simple dialog
box, but you missed the point - this is a test case to check if there
is a leak or not.

I repeated the test in windows and I do not see "delayd release".
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Viktor | last post by:
Which GUI is the most stable one? I don't need any fancy looking widgets (look and feel doesn't realy matter to me), I "just" need it to be rock stable and fast...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
17
by: José Joye | last post by:
Hi, I have implemented a Service that is responsible for getting messages from a MS MQ located on a remote machine. I'm getting memory leak from time to time (???). In some situation, it is...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
23
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
1
by: Joe Peterson | last post by:
I've been doing a lot of searching on the topic of one of Python's more disturbing issues (at least to me): the fact that if a __del__ finalizer is defined and a cyclic (circular) reference is...
3
by: frikk | last post by:
Hey everyone. I have been working with python for a couple years now, but just recently built my first program with a GUI. I decided to start with Tkinter since it is included with the base...
22
by: Peter | last post by:
I am using VS2008. I have a Windows Service application which creates Crystal Reports. This is a multi theaded application which can run several reports at one time. My problem - there is a...
2
by: Kevin McKinley | last post by:
# I posted a few days ago about a memory leak that I think i'm having with my first Tkinter program. # I've had trouble pinpointing what is wrong so i thought i would submit the code and see if...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.