[reportlab-users] memory leak in reportlab xmllib.FastXMLParser
Robin Becker
robin at reportlab.com
Tue Dec 17 15:06:51 EST 2013
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 <mirko.dziadzka at gmail.com> 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 <robin at reportlab.com> 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
>> reportlab-users at lists2.reportlab.com
>> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
--
Robin Becker
More information about the reportlab-users
mailing list