GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixes a memory leak where each spines' path was a view of the spine path by mdboom · Pull Request #89 · matplotlib/matplotlib

Conversation

@mdboom

@mdboom 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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mdboom added 2 commits April 21, 2011 12:26
@mdboom
Fixes a memory leak where each spines' path was a view of the spine p…
677218b
…ath of the previous run.
@mdboom
Remove the copy altogether. Testing reveals that it isn't necessary.
074570e
mdboom added a commit that referenced this pull request Apr 25, 2011
@mdboom
Merged pull request #89 from mdboom/spines_memory_leak.
0ce57c3
Fixes a memory leak where each spines' path was a view of the spine path
@mdboom
mdboom merged commit 0ce57c3 into matplotlib:v1.0.x Apr 25, 2011
@richbwood richbwood mentioned this pull request Dec 19, 2012
test_pcolormesh hangs #1609
Closed
magnunor pushed a commit to magnunor/matplotlib that referenced this pull request Dec 5, 2013
@francisco-dlp
Merge pull request matplotlib#89 from francisco-dlp/FIX-msa
b6d6b6a
Fix msa
@mdboom
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
@fariza
Merge pull request matplotlib#89 from fariza/universal-wheel
901db26
adding setup.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@mdboom
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.