Re: memory leak in reportlab xmllib.FastXMLParser

Robin Becker <[email protected]>
Newsgroups gmane.comp.python.reportlab.user
Message-ID <CAOBYczodU2xTaQj2D5hcVq3qOjuYuxJUXvYZK3LXFJ_cAKJWcw@mail.gmail.com>
I knew this would be the case; the problem is how to guarantee that
the parser gets collected properly in every case. I think this can be
done in Paragraph._setup, but there may be a way to use weak
references to ensure that the fast parser's __del__ is closed. A
solution in the fast parser would be preferable.

On 17 December 2013 19:35, Mirko Dziadzka <[email protected]> wrote:
> This solves the immediate problem. However, the problem reappear on higher levels.
>
> All code using ParaParser must call close() to  free the memory.
>
> But even reportlab internal code does not do this in every case.
> The program below reconstruct the memory leak on a higher level.
>
>
> import  gc
>
> from reportlab.platypus.paragraph import Paragraph
> from reportlab.lib.styles import ParagraphStyle
>
> normalStyle = ParagraphStyle('normal')
>
> # construct input which can not be decoded as utf-8
> # this will throw an exception in the parser
> brokenInput = unichr(228).encode("iso-8859-1")
>
> while True:
>     try:
>         p = Paragraph(brokenInput, normalStyle)
>     except Exception, e:
>         # will complain about invalid encoding ....
>         # NOTE that I have NO WAY of cleaning up the memory here ...
>         pass
>     gc.collect()
>
>
>
>
> On 17.12.2013, at 18:53, Robin Becker <[email protected]> wrote:
>
>> I find this fixes the issue
>>
>>> diff -r d7705185366c src/reportlab/lib/xmllib.py
>>> --- a/src/reportlab/lib/xmllib.py       Tue Dec 17 13:58:46 2013 +0000
>>> +++ b/src/reportlab/lib/xmllib.py       Tue Dec 17 17:52:50 2013 +0000
>>> @@ -524,6 +524,8 @@
>>>         try:
>>>             self.parser.close()
>>>         finally:
>>> +            self.feed = None
>>> +            del self.parser
>>>             self.parser = None
>>>
>>>     # Interface -- translate references
>>
>> I will check this in the trunk code tomorrow
>>
>>
>> On 17/12/2013 17:35, Mirko Dziadzka wrote:
>>>
>> ...........
>>
>> --
>> Robin Becker
>> _______________________________________________
>> reportlab-users mailing list
>> [email protected]
>> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
> _______________________________________________
> reportlab-users mailing list
> [email protected]
> http://two.pairlist.net/mailman/listinfo/reportlab-users



-- 
Robin Becker
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.