Repository navigation
Fixes a memory leak where each spines' path was a view of the spine path - #89
Merged
Merged
Conversation
mdboom
added a commit
that referenced
this pull request
Apr 25, 2011
Fixes a memory leak where each spines' path was a view of the spine path
Closed
magnunor
pushed a commit
to magnunor/matplotlib
that referenced
this pull request
Dec 5, 2013
fariza
added a commit
to fariza/matplotlib
that referenced
this pull request
Sep 22, 2016
adding setup.cfg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a memory leak where each spines' path was a view of the spine path of the previous run.
The following code (simplified to its essence from an example by Caleb Constantine) leaks memory very slowly -- detectable only using valgrind. It turns out that if the axes are cleared and reused rather than deleted, each spine's path is created as a view based on the spine's path in the previous draw. This creates a long reference chain rather than freeing the previous draw's path view.
This pull request fixes the leak, but @astraw may want to have a look at the fix... I'm not entirely sure why the copy is needed at all -- it hasn't actually been creating a copy all this time any way. Perhaps an alternative solution is just to remove the copy and the assignment (marked with the comment "# replace") altogether?
import numpy import matplotlib matplotlib.use("Agg") from matplotlib.figure import Figure from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas figure = Figure(dpi=None) canvas = FigureCanvas(figure) axes = figure.add_subplot(1,1,1) def draw(channel, seconds): axes.clear() axes.plot(channel, seconds) canvas.print_figure('test.png') channel = numpy.sin(numpy.arange(1000)) seconds = numpy.arange(len(channel)) for i in range(10): draw(channel, seconds)