I've been developing a software, which needs to download a web page periodically. When developing it, I noticed that the usage of urllib, httplib or raw sockets communication (as described in the source code included) leads to a memory leak. Every time when either urllib.urlopen, urlretrieve, similar functionality with httplib or the code below is executed, memory consumption is increased by something like 1 kilobyte.
I noticed the memory leak when my application was stress tested by my friend on his phone. After couple hours of running, the application malfunctioned and phone threw an error message of being low on memory. After that, I examined the memory consumption of emulator's epoc.exe using Windows' task manager and was able to reproduce the memory leak.
After couple hours of trials and with the help of people at #pys60 ;-), I was able to isolate the problem to the network code and it can be reproduced using the code below.
It leaks approximately 4 kilobytes during couple seconds, which is appr. 1 kilobyte every time the code below is executed.
What to do next? Are all socket operations (Bluetooth GPS, all network operations etc.) affected?
The memory leak can be achieved also when urllib or httplib -specific code is executed within a loop.
from urllib import urlretrieve
from socket import *
appuifw.app.title = u"Pvalikko"
#appuifw.app.menu = [(u"Kirjoita uusi viesti", write_message), (u"Poista viesti", delete_message), (u"Asetukset", options)]
#while appuifw.app.body == lb:
while i == 0:
testsocket = socket( AF_INET, SOCK_STREAM )
testsocket.connect( ( "192.168.10.4", 80 ) )
#testsocket.settimeout( 3 )
HTTPReq = "GET /\n"
bytesSent = testsocket.send( HTTPReq )
#print len( HTTPReq )
testsocket = None
HTTPReq = None
bytesSent = None
i = 1
i = 0
j = 0