Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

large memory leak in new contour routine #6940

Closed
efiring opened this issue Aug 12, 2016 · 3 comments
Closed

large memory leak in new contour routine #6940

efiring opened this issue Aug 12, 2016 · 3 comments
Assignees
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Milestone

Comments

@efiring
Copy link
Member

efiring commented Aug 12, 2016

In master and in 1.5.1, the new C++ contour routine has a massive memory leak; the 'legacy' mode does not. The following script illustrates this; run it as-is and then with the 'legacy' kwarg uncommented for comparison. (The script is long only because it seems report_memory has been removed from cbook. Unless it has simply been moved elsewhere or renamed, we need to bring it back.)

import numpy as np
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
# from matplotlib.cbook import report_memory

import os, sys

def report_memory(i=0):  # argument may go away
    'return the memory consumed by process'
    from matplotlib.compat.subprocess import Popen, PIPE
    pid = os.getpid()
    if sys.platform == 'sunos5':
        try:
            a2 = Popen('ps -p %d -o osz' % pid, shell=True,
                       stdout=PIPE).stdout.readlines()
        except OSError:
            raise NotImplementedError(
                "report_memory works on Sun OS only if "
                "the 'ps' program is found")
        mem = int(a2[-1].strip())
    elif sys.platform.startswith('linux'):
        try:
            a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True,
                       stdout=PIPE).stdout.readlines()
        except OSError:
            raise NotImplementedError(
                "report_memory works on Linux only if "
                "the 'ps' program is found")
        mem = int(a2[1].split()[1])
    elif sys.platform.startswith('darwin'):
        try:
            a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True,
                       stdout=PIPE).stdout.readlines()
        except OSError:
            raise NotImplementedError(
                "report_memory works on Mac OS only if "
                "the 'ps' program is found")
        mem = int(a2[1].split()[0])
    elif sys.platform.startswith('win'):
        try:
            a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
                       stdout=PIPE).stdout.read()
        except OSError:
            raise NotImplementedError(
                "report_memory works on Windows only if "
                "the 'tasklist' program is found")
        mem = int(a2.strip().split()[-2].replace(',', ''))
    else:
        raise NotImplementedError(
            "We don't have a memory monitor for %s" % sys.platform)
    return mem


np.random.seed(0)
z = np.random.randn(500, 100)

for i in range(200):
    fig, ax = plt.subplots()
    ax.contourf(z)  # , corner_mask='legacy')
    fig.savefig('temp.png')
    plt.close(fig)
    if i % 10 == 0:
        print(i, report_memory(i))
@efiring efiring added status: confirmed bug Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Aug 12, 2016
@efiring
Copy link
Member Author

efiring commented Aug 12, 2016

Ah, yes, #5360 replaced cbook.report_memory with unit/memleak.py, but I don't see how to use it for a case such as the present one.

@jenshnielsen jenshnielsen added this to the 2.0 (style change major release) milestone Aug 12, 2016
@ianthomas23
Copy link
Member

Confirmed, major gaffe, fix on its way.

@tacaswell
Copy link
Member

Closed by #6942

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. status: confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants