canvas.draw() + pyqt4 memory leak

Hi

I have a loop that updates a graph by calling

self.fig.canvas.draw()

But every time it updates the graph, the memory usage goes up. If the program runs for one hour, the memory is gone (things start to run slow too). I’ve tried to close() objects but the only thing that brings back the ram memory is to close the whole application.

I have read this note in the documentation (but it applies to pyplot):

“If you are making a long sequence of figures, you need to be aware of one more thing: the memory requiredfor a figure is not completely released until the figure is explicitly closed with close(). Deleting all references to the figure, and/or using the window manager to kill the window in which the figure appears on the screen, is not enough, because pyplot maintains internal references until close() is called.”

What
could I do in pyqt4 to release the memory?

Thanks

···

Please provide a simple standalone script that demonstrates the problem.

Eric

···

On 06/15/2011 12:13 PM, zb wrote:

Hi

I have a loop that updates a graph by calling

self.fig.canvas.draw()

But every time it updates the graph, the memory usage goes up. If the
program runs for one hour, the memory is gone (things start to run slow
too). I've tried to close() objects but the only thing that brings back
the ram memory is to close the whole application.

I have read this note in the documentation (but it applies to pyplot):

"If you are making a long sequence of figures, you need to be aware of
one more thing: the memory requiredfor a figure is not completely
released until the figure is explicitly closed with close(). Deleting
all references to the figure, and/or using the window manager to kill
the window in which the figure appears on the screen, is not enough,
because pyplot maintains internal references until close() is called."

What could I do in pyqt4 to release the memory?

Thanks

Hi
You could try the example here:
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html
Look at the memory grow. It does the same in my program.
Cheers

···

— On Wed, 6/15/11, Eric Firing <efiring@…202…> wrote:

From: Eric Firing <efiring@…202…>
Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
To: matplotlib-users@lists.sourceforge.net
Date: Wednesday, June 15, 2011, 6:33 PM

On 06/15/2011 12:13 PM, zb wrote:

Hi

I have a loop that updates a graph by calling

self.fig.canvas.draw()

But every time it updates the graph, the memory usage goes up. If the

program runs for one hour, the memory is gone (things start to run slow

too). I’ve tried to close() objects but the only thing that brings back
the ram memory is to close the whole application.

I have read this note in the documentation (but it applies to pyplot):

“If you are making a long sequence of figures, you need to be aware of
one more thing: the memory requiredfor a figure is not completely
released until the figure is explicitly closed with close(). Deleting
all references to the figure, and/or using the window manager to kill
the window in which the figure appears on the screen, is not enough,
because pyplot maintains internal references until close() is called.”

What could I do in pyqt4 to release the memory?

Thanks

Please provide a simple standalone script that demonstrates the
problem.

Eric


EditLive Enterprise is the world’s most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi

You could try the example here:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html

Look at the memory grow. It does the same in my program.

I added a call to cbook.report_memory, and shortened the timer to 0.1 seconds in the attached version.

There is no memory leakage evident when I run this on my system.

Eric

testqt4.py (4.03 KB)

···

On 06/15/2011 01:15 PM, zb wrote:

Cheers

--- On *Wed, 6/15/11, Eric Firing /<efiring@...202...>/* wrote:

    From: Eric Firing <efiring@...202...>
    Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
    To: matplotlib-users@lists.sourceforge.net
    Date: Wednesday, June 15, 2011, 6:33 PM

    On 06/15/2011 12:13 PM, zb wrote:
     > Hi
     >
     > I have a loop that updates a graph by calling
     >
     > self.fig.canvas.draw()
     >
     > But every time it updates the graph, the memory usage goes up. If the
     > program runs for one hour, the memory is gone (things start to
    run slow
     > too). I've tried to close() objects but the only thing that
    brings back
     > the ram memory is to close the whole application.
     >
     > I have read this note in the documentation (but it applies to
    pyplot):
     >
     > "If you are making a long sequence of figures, you need to be
    aware of
     > one more thing: the memory requiredfor a figure is not completely
     > released until the figure is explicitly closed with close(). Deleting
     > all references to the figure, and/or using the window manager to kill
     > the window in which the figure appears on the screen, is not enough,
     > because pyplot maintains internal references until close() is
    called."
     >
     > What could I do in pyqt4 to release the memory?
     >
     > Thanks

    Please provide a simple standalone script that demonstrates the problem.

    Eric

Hi.
Sorry but that program does not even run. I am using
matplotlib-1.0.1.win32-py2.6.exe
It breaks with the error (I had to modified a little to get the full error):
UnboundLocalError: local variable ‘mem’ referenced before assignment
Traceback (most recent call last):
File…
File “C:\Python26\lib\site-packages\matplotlib\cbook.py”, line 1245, in report_memory
return mem
Looks like you are using a different matplotlib version.
Cheers

···

— On Wed, 6/15/11, Eric Firing <efiring@…202…> wrote:

From: Eric Firing <efiring@…202…>
Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
To:
matplotlib-users@lists.sourceforge.net
Date: Wednesday, June 15, 2011, 7:46 PM

On 06/15/2011 01:15 PM, zb wrote:

Hi

You could try the example here:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html

Look at the memory grow. It does the same in my program.

I added a call to cbook.report_memory, and shortened the timer to 0.1
seconds in the attached version.

There is no memory leakage evident when I run this on my system.

Eric

Cheers

— On Wed, 6/15/11, Eric Firing /<efiring@…202…>/ wrote:

From: Eric Firing <efiring@...202...>
Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
To: matplotlib-users@lists.sourceforge.net
Date: Wednesday, June 15, 2011, 6:33 PM

On 06/15/2011 12:13 PM, zb wrote:
 > Hi
 >
 > I have a loop that updates a graph by calling
 >
 > self.fig.canvas.draw()
 >
 > But every time it updates the graph, the memory usage goes up. If the
 > program runs

for one hour, the memory is gone (things start to

run slow
 > too). I've tried to close() objects but the only thing that
brings back
 > the ram memory is to close the whole application.
 >
 > I have read this note in the documentation (but it applies to
pyplot):
 >
 > "If you are making a long sequence of figures, you need to be
aware of
 > one more thing: the memory requiredfor a figure is not completely
 > released until the figure is explicitly closed with close(). Deleting
 > all references to the figure, and/or using the window manager to kill

the window in which the figure appears on the screen, is not enough,
> because pyplot maintains internal references until close() is
called."
>
> What could I do in pyqt4 to release the memory?
>
> Thanks

Please provide a simple standalone script that demonstrates the problem.

Eric

-----Inline Attachment Follows-----


EditLive Enterprise is the world’s most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev

-----Inline Attachment Follows-----


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

line 1245 of cbook.py is missing the windows platform. So windows cannot be tested.
def report_memory(i=0): # argument may go away
‘return the memory consumed by process’
from subprocess import Popen, PIPE
pid = os.getpid()
if sys.platform==‘sunos5’:
a2 = Popen(‘ps -p %d -o osz’ % pid, shell=True,
stdout=PIPE).stdout.readlines()
mem = int(a2[-1].strip())
elif sys.platform.startswith(‘linux’):
a2 = Popen(‘ps -p %d -o rss,sz’ % pid, shell=True,

stdout=PIPE).stdout.readlines()
mem = int(a2[1].split()[1])
elif sys.platform.startswith(‘darwin’):
a2 = Popen(‘ps -p %d -o rss,vsz’ % pid, shell=True,
stdout=PIPE).stdout.readlines()
mem = int(a2[1].split()[0])
return mem

···

— On Thu, 6/16/11, zb <zauborg@…9…> wrote:

From: zb <zauborg@…9…>
Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
To: “Eric Firing” <efiring@…202…>, matplotlib-users@lists.sourceforge.net
Date: Thursday, June 16, 2011, 10:15 AM

Hi.
Sorry but that program does not even run. I am using
matplotlib-1.0.1.win32-py2.6.exe
It breaks with the error (I had to modified a little to get the full error):
UnboundLocalError: local variable ‘mem’ referenced before assignment
Traceback (most recent call last):
File…
File “C:\Python26\lib\site-packages\matplotlib\cbook.py”, line 1245, in report_memory
return mem
Looks like you are using a different matplotlib version.
Cheers
— On Wed, 6/15/11, Eric Firing <efiring@…202…> wrote:

From: Eric Firing <efiring@…202…>
Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
To:
matplotlib-users@lists.sourceforge.net
Date: Wednesday, June 15, 2011, 7:46 PM

On 06/15/2011 01:15 PM, zb wrote:

Hi

You could try the example here:

http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html

Look at the memory grow. It does the same in my program.

I added a call to cbook.report_memory, and shortened the timer to 0.1
seconds in the attached version.

There is no memory leakage evident when I run this on my system.

Eric

Cheers

— On Wed, 6/15/11, Eric Firing /<efiring@…202…>/ wrote:

From: Eric Firing <efiring@...202...>
Subject: Re: [Matplotlib-users] canvas.draw() + pyqt4 memory leak
To: matplotlib-users@...1544...ceforge.net
Date: Wednesday, June 15, 2011, 6:33 PM

On 06/15/2011 12:13 PM, zb wrote:
 > Hi
 >
 > I have a loop that updates a graph by calling
 >
 > self.fig.canvas.draw()
 >
 > But every time it updates the graph, the memory usage goes up. If the
 > program runs

for one hour, the memory is gone (things start to

run slow
 > too). I've tried to close() objects but the only thing that
brings back
 > the ram memory is to close the whole application.
 >
 > I have read this note in the documentation (but it applies to
pyplot):
 >
 > "If you are making a long sequence of figures, you need to be
aware of
 > one more thing: the memory requiredfor a figure is not completely
 > released until the figure is explicitly closed with close(). Deleting
 > all references to the figure, and/or using the window manager to kill

the window in which the figure appears on the screen, is not enough,
> because pyplot maintains internal references until close() is
called."
>
> What could I do in pyqt4 to release the memory?
>
> Thanks

Please provide a simple standalone script that demonstrates the problem.

Eric

-----Inline Attachment Follows-----


EditLive Enterprise is the world’s most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility
Checking.
http://p.sf.net/sfu/ephox-dev2dev

-----Inline Attachment Follows-----


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

-----Inline Attachment Follows-----


EditLive Enterprise is the world’s most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev

-----Inline Attachment Follows-----


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

In the development version of mpl it can (I added it--but too recently for it to have gotten into 1.0.1), provided you have the "tasklist" executable, which I think is a free download from Microsoft.

If you would like to try it, you could include the new version, below, in your test script.

Eric

def report_memory(i=0): # argument may go away
     'return the memory consumed by process'
     from subprocess import Popen, PIPE
     pid = os.getpid()
     if sys.platform=='sunos5':
         a2 = Popen('ps -p %d -o osz' % pid, shell=True,
             stdout=PIPE).stdout.readlines()
         mem = int(a2[-1].strip())
     elif sys.platform.startswith('linux'):
         a2 = Popen('ps -p %d -o rss,sz' % pid, shell=True,
             stdout=PIPE).stdout.readlines()
         mem = int(a2[1].split()[1])
     elif sys.platform.startswith('darwin'):
         a2 = Popen('ps -p %d -o rss,vsz' % pid, shell=True,
             stdout=PIPE).stdout.readlines()
         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

···

On 06/16/2011 04:31 AM, zb wrote:

line 1245 of cbook.py is missing the windows platform. So windows cannot
be tested.