This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Memory leakage in SAX with exception
Type: Stage:
Components: XML Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: loewis Nosy List: facundobatista, loewis, nnorwitz, pandreetto
Priority: normal Keywords:

Created on 2002-07-31 15:02 by pandreetto, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (7)
msg11765 - (view) Author: Paolo Andreetto (pandreetto) Date: 2002-07-31 15:02
Trying the following test:

#!/usr/bin/python

import sys,string,StringIO,traceback,time,gc
import xml.sax,xml.sax.handler
gc.set_debug(gc.DEBUG_SAVEALL)

class SimpleHandler(xml.sax.handler.ContentHandler):
    def __init__(self):
        pass

    def startElement(self,name,attrs):
        print 'start ',name

    def endElement(self,name):
        print 'end ',name

    def characters(self,content):
        print content

class SimpleErrorHandler(xml.sax.handler.ErrorHandler):
    def __init__(self):
        pass
        
    def fatalError(self,e):
        print e

myHandler=SimpleHandler()
myErrHandler=SimpleErrorHandler()
data='<test>something</>'
while 1:
    gc.collect()
    print len(gc.garbage)
    
    try:
        #xml.sax.parseString(data,myHandler,myErrHandler)
        xml.sax.parseString(data,myHandler)
    except Exception, e:
        sinfo=sys.exc_info()
	traceback.print_tb(sinfo[2],None)
    time.sleep(1)

it seems that lots of object remain uncollectable.
Using the SimpleErrorHandler the behaviour of gc is
good but a memory leakage still remain (4Kb every 30
seconds).
Tests run on i386 with debian/Linux (sid), python 2.1.3
(Build of July 29th).

Thanks
msg11766 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-08-05 02:06
Logged In: YES 
user_id=21627

Your analysis of this result is wrong. Instead, the result
shows that all objects *are* collectible, and that there is
merely cyclic garbage in case of a parser error - this
garbage *will* be collected, unless you explicitly ask the
GC to save it (which you do in your example).
msg11767 - (view) Author: Paolo Andreetto (pandreetto) Date: 2002-08-05 08:25
Logged In: YES 
user_id=551296

This is correct, it's my fault, but removing the
gc.set_dubug instruction the situation doesn't change. The
script is just a simple test, my trouble comes from a memory
leakage into SOAPpy module which uses another SAX-based
XML-parser.
If you think the problem doesn't depends on the python core,
please close this bug.
Thanks
msg11768 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-09-22 09:12
Logged In: YES 
user_id=21627

There might indeed have been a memory leak in Python 2.1.3,
but I cannot reproduce this with Python 2.2 or CVS-Python
anymore. Can you please try a more recent version and see
whether the problem goes away?
msg11769 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-01-08 01:07
Logged In: YES 
user_id=33168

Paolo, can you confirm that this bug should be closed?
msg11770 - (view) Author: Paolo Andreetto (pandreetto) Date: 2003-01-08 14:50
Logged In: YES 
user_id=551296

With Python 2.3a1 (#2, Jan  1 2003, 18:44:29) there's no
memory leakage.
With Python 2.2.2 (#1, Jan  3 2003, 12:42:27) the problem
still occurs.
I've used debian (unstable) package for both versions of python.
msg11771 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2004-11-09 00:25
Logged In: YES 
user_id=752496

Fixed in 2.3, as the submitter posted.

.    Facundo
History
Date User Action Args
2022-04-10 16:05:32adminsetgithub: 36960
2002-07-31 15:02:10pandreettocreate