FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixes a memory leak where each spines' path was a view of the spine path by mdboom · Pull Request #89 · matplotlib/matplotlib · GitHub

Repository navigation

Fixes a memory leak where each spines' path was a view of the spine path - #89

Merged
mdboom merged 2 commits into
matplotlib:v1.0.xfrom
mdboom:spines_memory_leak
Apr 25, 2011
Merged

mdboom merged 2 commits into
matplotlib:v1.0.xfrom
mdboom:spines_memory_leak

Conversation

mdboom commented Apr 21, 2011

Copy link
Copy Markdown
Member

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)

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
mdboom merged commit 0ce57c3 into matplotlib:v1.0.x Apr 25, 2011
richbwood mentioned this pull request Dec 19, 2012
magnunor pushed a commit to magnunor/matplotlib that referenced this pull request Dec 5, 2013
mdboom deleted the spines_memory_leak branch March 3, 2015 18:44
fariza added a commit to fariza/matplotlib that referenced this pull request Sep 22, 2016
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL