You Are Here:

Community: Developer Discussion Boards

#1 Old Exclamation Memory leak within urllib, httplib and raw socket communications - 2006-02-20, 12:51

Join Date: Dec 2005
Posts: 2
_welho_
Offline
Registered User
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?

Code:
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:
        e32.ao_sleep(1)
        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 )
        #print bytesSent

        testsocket.recv(1024)
        #print testsocket.read(1024)
        testsocket.close()
        e32.ao_sleep(1)

        testsocket = None
        HTTPReq = None
        bytesSent = None
        
        del testsocket
        del HTTPReq

def terminate():
        global i
        i = 1

i = 0
j = 0

appuifw.app.exit_key_handler=terminate

main_menu()
The memory leak can be achieved also when urllib or httplib -specific code is executed within a loop.

Toni
Last edited by _welho_ : 2006-02-20 at 19:33.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ