Memory leak on programmatic usage

Iwan Vosloo <[email protected]> Fri, 02 Mar 2007 13:00:20 +0200
Newsgroups gmane.comp.python.spyce.general
Message-ID <[email protected]>
Hi there,

we have a memory leak when using Spyce programatically.  I attach a file
that reproduces the problem.  (We're on Rev 1200 of the svn branch at
https://svn.sourceforge.net/svnroot/spyce/branches/spyce-2.1 )

See the attached code: It seems that the TestResponse object passed to
spyceStringHandler is never released... (One such object is added for
each request made.)

I'd like to know if this leak is true for newer versions?  

Any help in finding the cause of the leak will be appreciated...

If you run the attached file, it will print out the number of instances
of objects of class "TestRequest" and "TestResponse".  I only get
TestResponses left over...

-i

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Spyce-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spyce-users
memoryleakbug.py (text/x-python, 1.4 KB)

import spyce
import os

class TestRequest(spyce.spyceRequest):
    _env = {'REQUEST_METHOD': 'GET',
            'REQUEST_URI': '/sd/d',
            'a': 'aaa'}

    _headers = {}
    
    def env(self, name=None):
        return self._env[name]
            
    def getHeader(self, type=None):
        return self._headers[type]
    
    def getServerID(self):
        os.getpid()


class TestResponse(spyce.spyceResponse):
    returncode = spyce.spyceResponse.RETURN_OK
    nop = lambda *args: None
    write = writeErr = close = clear = sendHeaders = nop
    setContentType = setReturnCode = addHeader = flush = unbuffer = nop


def logIt():
    import gc
    gc.collect()
    totals = {}
    for i in gc.get_objects():
       if isinstance(i, TestResponse) or isinstance(i, TestRequest):
          total = totals.get(i.__class__, 0)
          total += 1
          totals[i.__class__] = total
    for cls, number in totals.items():
       print '%s\t ocurrences of %s' % (number, cls)



def handleASingleRequest():
    spyceRequest = TestRequest()
    spyceResponse = TestResponse()
    
    
    spyce.spyceStringHandler(spyceRequest,
                             spyceResponse,
                             'stuff',
                             sig='',
                             args=[],
                             kwargs=None,
                             config=None)

for i in range(1000):
    handleASingleRequest()
logIt()