Repository navigation
Closed
Description
First, the relevant output of valgrind with --tool=memcheck --leak-check=full --show-leak-kinds=all:
==2657== 4,841,396 bytes in 2 blocks are still reachable in loss record 4,337 of 4,341
==2657== at 0x4C2BC79: operator new[](unsigned long) (vg_replace_malloc.c:384)
==2657== by 0x2D592353: RendererAgg::tostring_rgba_minimized(Py::Tuple const&) (_backend_agg.cpp:2382)
==2657== by 0x2D5A3363: Py::PythonExtension<RendererAgg>::method_varargs_call_handler(_object*, _object*) (ExtensionOldType.hxx:291)
==2657== by 0x54BB13: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x577BE1: ??? (in /usr/bin/python2.7)
==2657==
==2657== 55,424,972 bytes in 33 blocks are definitely lost in loss record 4,339 of 4,341
==2657== at 0x4C2BC79: operator new[](unsigned long) (vg_replace_malloc.c:384)
==2657== by 0x2D592353: RendererAgg::tostring_rgba_minimized(Py::Tuple const&) (_backend_agg.cpp:2382)
==2657== by 0x2D5A3363: Py::PythonExtension<RendererAgg>::method_varargs_call_handler(_object*, _object*) (ExtensionOldType.hxx:291)
==2657== by 0x54BB13: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x577BE1: ??? (in /usr/bin/python2.7)
==2657==
==2657== 56,230,256 bytes in 25 blocks are possibly lost in loss record 4,340 of 4,341
==2657== at 0x4C2BC79: operator new[](unsigned long) (vg_replace_malloc.c:384)
==2657== by 0x2D592353: RendererAgg::tostring_rgba_minimized(Py::Tuple const&) (_backend_agg.cpp:2382)
==2657== by 0x2D5A3363: Py::PythonExtension<RendererAgg>::method_varargs_call_handler(_object*, _object*) (ExtensionOldType.hxx:291)
==2657== by 0x54BB13: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x54C027: PyEval_EvalFrameEx (in /usr/bin/python2.7)
==2657== by 0x575D91: PyEval_EvalCodeEx (in /usr/bin/python2.7)
==2657== by 0x577BE1: ??? (in /usr/bin/python2.7)
==2657==
==2657== LEAK SUMMARY:
==2657== definitely lost: 55,490,524 bytes in 83 blocks
==2657== indirectly lost: 20,256 bytes in 407 blocks
==2657== possibly lost: 56,383,520 bytes in 481 blocks
==2657== still reachable: 11,403,937 bytes in 13,860 blocks
==2657== suppressed: 179,227,068 bytes in 27,533 blocks
I am drawing many maps (with basemap) with polygon collections using the agg backend and then save them as png or svg. I always close the figures and start fresh. The more I draw the higher the memory usage gets, which is why I ran memcheck. I will try to come up with a minimal example that reproduces this.
I am using mpl 1.3.1, basemap 1.0.7, Python 2.7.3.
Metadata
Metadata
Assignees
Labels
No labels
Activity
tacaswell commentedon Jul 8, 2014
you provide simple code to reproduce this? Does this also happen on master?
letmaik commentedon Jul 8, 2014
Right, I narrowed down the problem quite a lot. It's a combination of using agg, rasterized, and saving as svg:
There's no memory leak when one of the following is true: using another backend (e.g. cairo), not using rasterized, not using svg as output.
EDIT: removed unused code parts
tacaswell commentedon Jul 8, 2014
Looking at the source for
tostring_rgba_minimizeit looks like it allocates a buffer which it does not de-allocate, however the pointer gets handed off to eitherPy:Bytes(py3k) orPy:String(py2k) which the comments suggest should take over management of that pointer.letmaik commentedon Jul 8, 2014
I don't know about the internal structure of matplotlib, but I suspect that
tostring_rgba_minimizeis called to rasterize the circle (=buf), then it is included in the svg somewhere else, but the raster buffer is not freed there.tacaswell commentedon Jul 9, 2014
My point was that the code that allocates this buffer is not responsible for cleaning it up and that the valgrind might be a red herring.
letmaik commentedon Jul 9, 2014
I think you're right, after all valgrind doesn't tell you where the leak is. Just to confirm, you can reproduce the memory increase using the test script, right?
tacaswell commentedon Jul 9, 2014
I have not had time to really dig into this. I think @efiring has done a good deal of work on memory leaks.
dopplershift commentedon Jul 11, 2014
We're using the PyCXX API (and hence Python C-API) incorrectly. The functions we use make copies of the buffer and do not assume ownership. I'm working on a patch to have Python allocate the memory and give us the pointer, so that we no long leak and avoid the copy.
Fix memory leak in tostring_rgba_minimize(). (matplotlib#3197)
Fix memory leak in tostring_rgba_minimize(). (matplotlib#3197)
Merge pull request #3207 from dopplershift/fix_memory_leak
tacaswell commentedon Jul 12, 2014
@neothemachine This should be fixed, closing. Please ping us if that isn't true.
letmaik commentedon Jul 14, 2014
Will this be in 1.3.x as well? That would be good, as I just realized that
rasterizedis not supported by the cairo backend, so there's no workaround for me at the moment if I want to keep using svg's.tacaswell commentedon Jul 14, 2014
At this point we have no plans for 1.3.2
We just tagged the first rc for 1.4.0
On Jul 14, 2014 7:04 AM, "Maik Riechert" notifications@github.com wrote:
letmaik commentedon Jul 14, 2014
Ok, I will wait for 1.4.0 then. In the meantime I will install the rc and check the fix.
tacaswell commentedon Jul 14, 2014
Yes, please test the rc
Fix memory leak in tostring_rgba_minimize(). (matplotlib#3197)