[reportlab-users] Releasing memory used by Report Lab
jerrycasiano at gmail.com
Thu May 6 08:50:53 EDT 2010
On Thu, 2010-05-06 at 10:25 +0100, Robin Becker wrote:
Thanks for the quick reply.
> Anyhow I suspect you may have some preconceptions about how this stuff works.
> The rl toolkit doesn't control any memory directly it's all controlled by
> python. However, we do maintain some global variables that are used to store
> fonts and they may be the problem you're looking at. You can reset the state of
> the toolkit as much as we know how by calling the reportlab.rl_config._reset()
> function when you've finished with reportlab. In this case that's either at the
> end of the BuildPDF.__init__ or in the _build_pdf callback. So you need to do
> something like
> def _build_pdf(unused_widget):
> if FONTDIR:
> BuildPDF('Sample Sheet', FONTDIR, OUTPUT, PANGRAM)
> from reportlab.rl_config import _reset
> #if exists(OUTPUT):
Ah, so I was on the right track. I started by clearing the added fonts
from pdfmetrics._fonts, when that had no effect I found the _reset in
rl_config and gave that a shot. But it just looked wrong to me, probably
because of the leading _ so I was hoping there was something else I
> that should clean up the stuff that reportlab is holding onto. However, that
> doesn't guarantee that all the memory will be returned to the system; that's up
> to python and the way it & the system manage memory.
Yup, I was afraid of that.
> If you really want to free up this memory a better way to do this is to make
> your gui execute the document generation as a child process (see the subprocess
> library module documentation). That way all of the memory used by the subprocess
> will automatically be reclaimed when the process dies.
I'm starting to think that may end up being the cleanest way to do it
Thanks again. :-)
More information about the reportlab-users