Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Dec 2005

    Exclamation Memory leak within urllib, httplib and raw socket communications

    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?

    import appuifw
    import e32
    import e32db
    import urllib
    from urllib import urlretrieve
    import httplib
    import time
    from socket import *
    def main_menu():
        global i
        global update_interval
        global update_list
        global j
        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( ( "", 80 ) )
            #testsocket.settimeout( 3 )
            HTTPReq = "GET /\n"
            bytesSent = testsocket.send( HTTPReq )
            #print len( HTTPReq )
            #print bytesSent
            #print testsocket.read(1024)
            testsocket = None
            HTTPReq = None
            bytesSent = None
            del testsocket
            del HTTPReq
    def terminate():
            global i
            i = 1
    i = 0
    j = 0
    The memory leak can be achieved also when urllib or httplib -specific code is executed within a loop.

    Last edited by _welho_; 2006-02-20 at 18:33.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts