[Matplotlib-users] memory leak on MacOS with TkAgg

2014-10-22 Thread Russell Owen
I'm seeing a memory leak with calls to subplot.clear() and canvas.draw() 
on MacOS. The same code shows no leakage on unix.

Here is a simple script that demonstrates the problem.

#!/usr/bin/env python
from __future__ import division
Demonstrate a memory leak in matplotlib on MacOS with TkAgg

Variants:
- Comment out subplot.clear(): this reduces the leak by about 4/5
- Comment out canvas.draw(): this reduces the leak by about 1/5
- Comment out both: there should be essentially no leakage

The leak rate seems to be affected by the update rate
(larger update interval causes lower leakage),
which suggests it's not a simple x amount of leakage per call.

import resource
import time
import Tkinter
import matplotlib
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

class MemoryLeaker(Tkinter.Frame):
 Demonstrate a memory leak in matplotlib
 
 def __init__(self, master, updateInterval=0.1, updatesPerReport=25):
 Construct a MemoryLeaker

 Inputs:
 - master: master widget
 - updateInterval: interval at which subplot.clear and 
canvas.draw are called
 - updatesPerReport: number of updates between memory reports
 
 Tkinter.Frame.__init__(self, master)

 self._updateInterval = float(updateInterval)
 self._updatesPerReport = int(updatesPerReport)

 self.figure = matplotlib.figure.Figure(figsize=(8, 2), 
frameon=True)
 self.canvas = FigureCanvasTkAgg(self.figure, self)
 self.canvas.get_tk_widget().grid(row=0, column=0, sticky=news)
 self.subplot = self.figure.add_subplot(1, 1, 1)

 print time max RSSleak rate
 print (sec) (kb)  (kb/sec)
 self._prevTime = time.time()
 self._prevMem = float(nan)
 self._reportCount = 0

 self.updatePlot()

 def updatePlot(self):
 Update the plot; calls itself at the update interval
 
 if self._reportCount == 0:
 self.reportMem()
 self._reportCount = (self._reportCount + 1) % 
self._updatesPerReport

 self.subplot.clear()
 self.canvas.draw()
 self.after(int(self._updateInterval * 1000), self.updatePlot)

 def reportMem(self):
 currTime = time.time()
 dTime = currTime - self._prevTime
 res = resource.getrusage(resource.RUSAGE_SELF)
 currMem = res.ru_maxrss / 1024 # maximum resident set size 
utilized (in kb)
 leakRate = (currMem - self._prevMem) / dTime
 self._prevTime = currTime
 self._prevMem = currMem
 print %6.1f   %6d%6.1f % (dTime, currMem, leakRate)


if __name__ == __main__:
 root = Tkinter.Tk()
 wdg = MemoryLeaker(root, updateInterval=0.1, updatesPerReport=25)
 wdg.pack(expand=True, fill=both)

 root.mainloop()

P.S. my current setup is:
- MacOS 10.9
- python.org python 2.7.8
- matploblib 1.3.1
- a pre-release of Tcl/Tk 8.5.17
but I've seen this on many earlier versions, as well

I have not tried it with matplotlib 1.4.1 yet (due to problems packaging 
that with py2app).


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


[Matplotlib-users] Memory leak when using pyplot.ion() ?

2014-01-17 Thread OCuanachain, Oisin (Oisin)
Hi,

I am having problems with a script. It runs a number of iterations and plots 
and saves a number of plots on each iteration. After the plots have been saved 
I issue the pyplot.close('all') command so despite many plots being created 
only 4 should be open at any given time which should not cause any memory 
problems. When I run the script however I see the RAM usage gradually growing 
without bound and eventually causing the script to crash. Interestingly I have 
found if I comment out the pyplot.ion()  and pyplot.ioff() the problem 
vanishes. So I do have a workaround but it would still be good to have this 
fixed.

My OS is Windows XP Service Pack 3
Python 2.6
Matplotlib 1.3.1

The code below is a stripped down version of my script which still exhibits the 
problem. Interestingly if I set the number of iterations such that it won't run 
out of memory before the script completes then one final call to 
pyplot.close('all') will release all the memory. It almost looks like there is 
some sort of 'race condition' between the close('all') at the end of  one 
iteration and the plot commands in the next iteration which create new figures. 
In the taskbar Windows shows the number of windows associated with each 
application = while this script runs I expect to see between 1 and 5 windows 
(interpreter + 1-4 figures), however as the script progresses and the memory 
usage grows Windows lists a growing number of windows associated with Python 
(multiple instances of figure1/2/3/4).

Oisín.

# -*- coding: utf-8 -*-
import sys
import time
import numpy as np
from matplotlib import pyplot
import os
  # Main script body
try:
  for gain in range(1,20,2):
  for PortToTest in range(8):
dirname = '.\crash'
runname = '\P' + str(PortToTest) + str(gain) + \
  '_' + time.strftime('d%dh%Hm%Ms%S')
dirname = dirname + runname
os.mkdir(dirname)
os.system('copy ' + sys.argv[0] + ' ' + dirname )
nIts= 50
echoPlotDec = 10
ResidN = np.random.rand(4,100)
MaxSl  = np.random.rand(4,100)
MaxOld = np.random.rand(4,100)
MaxNew = np.random.rand(4,100)
EchoA  = np.random.rand(100,160)
pyplot.ion()
pyplot.figure()
pyplot.plot(np.transpose(ResidN),'.-')
pyplot.savefig(dirname + '\\results.png',format='png')
pyplot.figure()
pyplot.plot(np.transpose(EchoA[0:nIts-1:echoPlotDec,:]),'.-')
pyplot.plot(np.transpose(EchoA[nIts:2*nIts-1:echoPlotDec,:]),'*-')
pyplot.savefig(dirname + '\\CoefsA.png',format='png')
pyplot.figure()
pyplot.plot(np.transpose(MaxOld),'.-')
pyplot.plot(np.transpose(MaxNew),'*-')
pyplot.savefig(dirname + '\\MaxAbsA.png',format='png')
pyplot.figure()
pyplot.plot(np.transpose(MaxSl),'.-')
pyplot.savefig(dirname + '\\MaxAbsSl.png',format='png')
pyplot.close('all')
except RuntimeError, msg:
  print 'Exception occurred in main script body'
  print sys.stderr, msg
  raise
finally:
  print Test done
  # Display plots
  pyplot.ioff()
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak when using pyplot.ion() ?

2013-10-14 Thread OCuanachain, Oisin (Oisin)
Hi,

I am having problems with a script. It runs a number of iterations and plots 
and saves a number of plots on each iteration. After the plots have been saved 
I issue the pyplot.close('all') command so despite many plots being created 
only 4 should be open at any given time which should not cause any memory 
problems. When I run the script however I see the RAM usage gradually growing 
without bound and eventually causing the script to crash. Interestingly I have 
found if I comment out the pyplot.ion()  and pyplot.ioff() the problem 
vanishes. So I do have a workaround but it would still be good to have this 
fixed in case I forget about it in future and loose another weekend's work.

My OS is Windows XP Service Pack 3
Python 2.6
Matplotlib 1.0.1

The code below is a stripped down version of my script which still exhibits the 
problem.

Oisín.

# -*- coding: utf-8 -*-

import sys
import time
import numpy as np
from matplotlib import pyplot
import os

  # Main script body
try:

  for gain in range(1,20,2):

  for PortToTest in range(8):

dirname = '.\crash'
f = open(dirname + '\\results.m','w')

runname = '\P' + str(PortToTest) + str(gain) + \
  '_' + time.strftime('d%dh%Hm%Ms%S')

dirname = dirname + runname
os.mkdir(dirname)
os.system('copy ' + sys.argv[0] + ' ' + dirname )

nIts = 50
# Decimate  data for plotting if many iterations are run
if(nIts10):
  echoPlotDec = 10
else:
  echoPlotDec = 1
ResidN   = np.zeros((4,2*nIts))
MaxSl= np.zeros((4,2*nIts))
MaxOld   = np.zeros((4,2*nIts))
MaxNew   = np.zeros((4,2*nIts))
EchoA= np.zeros((2*nIts,160))

for kk in range(2*nIts):

ResidN[0,kk] = np.random.rand(1,1)
ResidN[1,kk] = np.random.rand(1,1)
ResidN[2,kk] = np.random.rand(1,1)
ResidN[3,kk] = np.random.rand(1,1)

MaxSl[0,kk] = np.random.rand(1,1)
MaxSl[1,kk] = np.random.rand(1,1)
MaxSl[2,kk] = np.random.rand(1,1)
MaxSl[3,kk] = np.random.rand(1,1)

MaxOld[0,kk] = np.random.rand(1,1)
MaxOld[1,kk] = np.random.rand(1,1)
MaxOld[2,kk] = np.random.rand(1,1)
MaxOld[3,kk] = np.random.rand(1,1)

MaxNew[0,kk] = np.random.rand(1,1)
MaxNew[1,kk] = np.random.rand(1,1)
MaxNew[2,kk] = np.random.rand(1,1)
MaxNew[3,kk] = np.random.rand(1,1)

EchoA[kk,:] = np.random.rand(1,160)

f.close()

pyplot.ion()

pyplot.figure()
pyplot.hold(True)

LegendTexts = (A,B,C,D)

pyplot.title(R ( + runname +))
pyplot.xlabel(Index)
pyplot.ylabel(Noise (dB))
pyplot.grid(True)
pyplot.hold(True)
pyplot.plot(np.transpose(ResidN),'.-')
pyplot.legend(LegendTexts,loc=1)
pyplot.axis([0, 2*nIts, -33, -25])
pyplot.savefig(dirname + '\\results.emf',format='emf')

pyplot.figure()
pyplot.hold(True)

pyplot.title(Coefs)
pyplot.xlabel(Coef Index)
pyplot.ylabel(Coef Value)
pyplot.grid(True)
pyplot.hold(True)
pyplot.plot(np.transpose(EchoA[0:nIts-1:echoPlotDec,:]),'.-')
pyplot.plot(np.transpose(EchoA[nIts:2*nIts-1:echoPlotDec,:]),'*-')
pyplot.axis([0, 160, -0.5, 2])
pyplot.savefig(dirname + '\\CoefsA.emf',format='emf')

pyplot.figure()
pyplot.hold(True)

pyplot.title(MaxAbs, Old = '.', New = '*' )
pyplot.xlabel(Iteration)
pyplot.ylabel(o/p (LSBs))
pyplot.grid(True)
pyplot.hold(True)
pyplot.plot(np.transpose(MaxOld),'.-')
pyplot.plot(np.transpose(MaxNew),'*-')
pyplot.axis([0, 2*nIts, 32, 128])
pyplot.savefig(dirname + '\\MaxAbsA.emf',format='emf')

pyplot.figure()
pyplot.hold(True)

pyplot.title(MaxAbs)
pyplot.xlabel(Iteration)
pyplot.ylabel((LSBs))
pyplot.grid(True)
pyplot.hold(True)
pyplot.plot(np.transpose(MaxSl),'.-')
pyplot.axis([0, 2*nIts, 0, 64])
pyplot.savefig(dirname + '\\MaxAbsSl.emf',format='emf')

pyplot.close('all')

except RuntimeError, msg:
  print 'Exception occurred in main script body'
  print sys.stderr, msg
  raise
finally:
  print Test done
  # Display plots
  pyplot.ioff()


--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register 
http://pubads.g.doubleclick.net/gampad/clk?id=60134071iu=/4140/ostg.clktrk___
Matplotlib-users mailing list

Re: [Matplotlib-users] Memory leak when using pyplot.ion() ?

2013-10-14 Thread Michael Droettboom
I haven't had a chance to look into where the memory is actually 
leaking, ion/ioff are intended for interactive use, and here you are 
saving a large number of plots to files.  Why do you need ion at all?


Mike

On 10/14/2013 08:51 AM, OCuanachain, Oisin (Oisin) wrote:


Hi,

I am having problems with a script. It runs a number of iterations and 
plots and saves a number of plots on each iteration. After the plots 
have been saved I issue the pyplot.close('all') command so despite 
many plots being created only 4 should be open at any given time which 
should not cause any memory problems. When I run the script however I 
see the RAM usage gradually growing without bound and eventually 
causing the script to crash. Interestingly I have found if I comment 
out the pyplot.ion()  and pyplot.ioff() the problem vanishes. So I do 
have a workaround but it would still be good to have this fixed in 
case I forget about it in future and loose another weekend's work.


My OS is Windows XP Service Pack 3

Python 2.6

Matplotlib 1.0.1

The code below is a stripped down version of my script which still 
exhibits the problem.


Oisín.

# -*- coding: utf-8 -*-

import sys

import time

import numpy as np

from matplotlib import pyplot

import os

  # Main script body

try:

  for gain in range(1,20,2):

  for PortToTest in range(8):

dirname = '.\crash'

f = open(dirname + '\\results.m','w')

runname = '\P' + str(PortToTest) + str(gain) + \

  '_' + time.strftime('d%dh%Hm%Ms%S')

dirname = dirname + runname

os.mkdir(dirname)

os.system('copy ' + sys.argv[0] + ' ' + dirname )

nIts = 50

# Decimate  data for plotting if many iterations are run

if(nIts10):

  echoPlotDec = 10

else:

  echoPlotDec = 1

ResidN   = np.zeros((4,2*nIts))

MaxSl= np.zeros((4,2*nIts))

MaxOld   = np.zeros((4,2*nIts))

MaxNew   = np.zeros((4,2*nIts))

EchoA= np.zeros((2*nIts,160))

for kk in range(2*nIts):

ResidN[0,kk] = np.random.rand(1,1)

ResidN[1,kk] = np.random.rand(1,1)

ResidN[2,kk] = np.random.rand(1,1)

ResidN[3,kk] = np.random.rand(1,1)

MaxSl[0,kk] = np.random.rand(1,1)

MaxSl[1,kk] = np.random.rand(1,1)

MaxSl[2,kk] = np.random.rand(1,1)

MaxSl[3,kk] = np.random.rand(1,1)

MaxOld[0,kk] = np.random.rand(1,1)

MaxOld[1,kk] = np.random.rand(1,1)

MaxOld[2,kk] = np.random.rand(1,1)

MaxOld[3,kk] = np.random.rand(1,1)

MaxNew[0,kk] = np.random.rand(1,1)

MaxNew[1,kk] = np.random.rand(1,1)

MaxNew[2,kk] = np.random.rand(1,1)

MaxNew[3,kk] = np.random.rand(1,1)

EchoA[kk,:] = np.random.rand(1,160)

f.close()

pyplot.ion()

pyplot.figure()

pyplot.hold(True)

LegendTexts = (A,B,C,D)

pyplot.title(R ( + runname +))

pyplot.xlabel(Index)

pyplot.ylabel(Noise (dB))

pyplot.grid(True)

pyplot.hold(True)

pyplot.plot(np.transpose(ResidN),'.-')

pyplot.legend(LegendTexts,loc=1)

pyplot.axis([0, 2*nIts, -33, -25])

pyplot.savefig(dirname + '\\results.emf',format='emf')

pyplot.figure()

pyplot.hold(True)

pyplot.title(Coefs)

pyplot.xlabel(Coef Index)

pyplot.ylabel(Coef Value)

pyplot.grid(True)

pyplot.hold(True)

pyplot.plot(np.transpose(EchoA[0:nIts-1:echoPlotDec,:]),'.-')

pyplot.plot(np.transpose(EchoA[nIts:2*nIts-1:echoPlotDec,:]),'*-')

pyplot.axis([0, 160, -0.5, 2])

pyplot.savefig(dirname + '\\CoefsA.emf',format='emf')

pyplot.figure()

pyplot.hold(True)

pyplot.title(MaxAbs, Old = '.', New = '*' )

pyplot.xlabel(Iteration)

pyplot.ylabel(o/p (LSBs))

pyplot.grid(True)

pyplot.hold(True)

pyplot.plot(np.transpose(MaxOld),'.-')

pyplot.plot(np.transpose(MaxNew),'*-')

pyplot.axis([0, 2*nIts, 32, 128])

pyplot.savefig(dirname + '\\MaxAbsA.emf',format='emf')

pyplot.figure()

pyplot.hold(True)

pyplot.title(MaxAbs)

pyplot.xlabel(Iteration)

pyplot.ylabel((LSBs))

pyplot.grid(True)

pyplot.hold(True)

pyplot.plot(np.transpose(MaxSl),'.-')

pyplot.axis([0, 2*nIts, 0, 64])

pyplot.savefig(dirname + '\\MaxAbsSl.emf',format='emf')

pyplot.close('all')

except RuntimeError, msg:

  print 'Exception occurred in main script body'

  print sys.stderr, msg

  raise

finally:

  print Test done

  # Display plots

  pyplot.ioff()



--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts 

Re: [Matplotlib-users] Memory leak when using pyplot.ion() ?

2013-10-14 Thread Mark Lawrence
On 14/10/2013 13:51, OCuanachain, Oisin (Oisin) wrote:
 Hi,

 I am having problems with a script. It runs a number of iterations and
 plots and saves a number of plots on each iteration. After the plots
 have been saved I issue the pyplot.close(‘all’) command so despite many
 plots being created only 4 should be open at any given time which should
 not cause any memory problems. When I run the script however I see the
 RAM usage gradually growing without bound and eventually causing the
 script to crash. Interestingly I have found if I comment out the
 pyplot.ion()  and pyplot.ioff() the problem vanishes. So I do have a
 workaround but it would still be good to have this fixed in case I
 forget about it in future and loose another weekend’s work.

 My OS is Windows XP Service Pack 3
 Python 2.6
 Matplotlib 1.0.1


Is this actually a matplotlib problem or could it be a Windows problem 
as discussed here http://bugs.python.org/issue19246 ?

-- 
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence


--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register 
http://pubads.g.doubleclick.net/gampad/clk?id=60134071iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak when using pyplot.ion() ?

2013-10-14 Thread Goyo
2013/10/14 Mark Lawrence breamore...@yahoo.co.uk:
 On 14/10/2013 13:51, OCuanachain, Oisin (Oisin) wrote:
 Hi,

 I am having problems with a script. It runs a number of iterations and
 plots and saves a number of plots on each iteration. After the plots
 have been saved I issue the pyplot.close(‘all’) command so despite many
 plots being created only 4 should be open at any given time which should
 not cause any memory problems. When I run the script however I see the
 RAM usage gradually growing without bound and eventually causing the
 script to crash. Interestingly I have found if I comment out the
 pyplot.ion()  and pyplot.ioff() the problem vanishes. So I do have a
 workaround but it would still be good to have this fixed in case I
 forget about it in future and loose another weekend’s work.

 My OS is Windows XP Service Pack 3
 Python 2.6
 Matplotlib 1.0.1


 Is this actually a matplotlib problem or could it be a Windows problem
 as discussed here http://bugs.python.org/issue19246 ?

I think this is different. That bug report is not about RAM usage
growing without bound but memory allocation failing with plenty of RAM
available.

Goyo

--
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register 
http://pubads.g.doubleclick.net/gampad/clk?id=60134071iu=/4140/ostg.clktrk
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak involving matplotlib in webapplication

2011-10-13 Thread Viktor Forsman
Hi,

I have problems with a memory leak in a webapplication involving matplotlib.
Basically, I have a function which usies the OO way of generating the graph,
printing it to a StringIO object and returning that. I've posted a question
with the details on stackoverflow (
http://stackoverflow.com/questions/7740832/need-help-identifying-a-memory-leak-involving-matplotlib-and-flask).
Any ideas are highly appreciated.
--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak involving matplotlib in webapplication

2011-10-13 Thread John Hunter
On Thu, Oct 13, 2011 at 12:42 AM, Viktor Forsman
viktor.fors...@gmail.com wrote:
 Hi,

 I have problems with a memory leak in a webapplication involving matplotlib.
 Basically, I have a function which usies the OO way of generating the graph,
 printing it to a StringIO object and returning that. I've posted a question
 with the details on stackoverflow
 (http://stackoverflow.com/questions/7740832/need-help-identifying-a-memory-leak-involving-matplotlib-and-flask).
 Any ideas are highly appreciated.

What version of matplotlib and numpy are you using?  Does it help to do:

import gc
gc.collect()

after a call to plot total or plot month?

Also, you appear to be adding data to plot_values and storing this
on every call.  Are you sure the leak is in mpl and not here?
JDH

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak involving matplotlib in webapplication

2011-10-13 Thread Viktor Forsman
I use matplotlib 1.1 and numpy 1.5.0

gc.collect() after the function call solved the problem! Thanks alot!

Den torsdagen den 13:e oktober 2011 skrev John Hunterjdh2...@gmail.com:
 On Thu, Oct 13, 2011 at 12:42 AM, Viktor Forsman
 viktor.fors...@gmail.com wrote:
 Hi,

 I have problems with a memory leak in a webapplication involving
matplotlib.
 Basically, I have a function which usies the OO way of generating the
graph,
 printing it to a StringIO object and returning that. I've posted a
question
 with the details on stackoverflow
 (
http://stackoverflow.com/questions/7740832/need-help-identifying-a-memory-leak-involving-matplotlib-and-flask
).
 Any ideas are highly appreciated.

 What version of matplotlib and numpy are you using?  Does it help to do:

import gc
gc.collect()

 after a call to plot total or plot month?

 Also, you appear to be adding data to plot_values and storing this
 on every call.  Are you sure the leak is in mpl and not here?
 JDH

--
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak - canvas.draw() + pyqt4

2011-10-08 Thread Matt Earnshaw
Hi Stoyan,

I had this problem, refer to
http://sourceforge.net/mailarchive/forum.php?thread_name=1315605880.26850.7.camel%40GARDENforum_name=matplotlib-users

It was dismissed as a code error (which I would perhaps dispute).

You have two options:-

- Adopt the approach seen here:
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.html

- Or use the work around:
import matplotlib
# Free memory
matplotlib.pyplot.close()

Regards
Matt Earnshaw

On Sat, Oct 8, 2011 at 9:22 PM, stoqn_veles...@mail.ru wrote:
 --
 Message: 7
 Date: Sat, 08 Oct 2011 21:22:45 +0400
 From: ? ???stoqn_veles...@mail.ru
 Subject: [Matplotlib-users] Memory leak - canvas.draw() + pyqt4
 To:matplotlib-users@lists.sourceforge.net
 Message-ID:e1rcabl-0002hq-00.stoqn_veleshki-mail...@f263.mail.ru
 Content-Type: text/plain; charset=utf-8

 Memory leak - canvas.draw() + pyqt4
 Hi, my name is Stoyan.
 ??? I use the following packages: python 2.6 , PyQt 4.8.5-1, numpy 1.6 and 
 matplotlib 1.0.1. In my program Matplotlib library I have used a GUI 
 application created by PyQt. In the program there is a loop that updates a 
 graph by calling:
 ?self.fig.canvas.draw()
 ?? But every time the graph is updated, the memory usage goes up.I the 
 address listed bellow there is an explanation of the reason for the issue 
 however, even though
 https://github.com/matplotlib/matplotlib/pull/89?
 ?? I have followed all instructions that have been specified in link,there is 
 still a flaw in the programme due to a memory leak, though not a big one.?? I 
 wondere whether there is alternative way to discharge this leak of memory and 
 if so could you assist in solving it.

--
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-12 Thread Friedrich Romstedt
2010/12/12 Russell Owen ro...@uw.edu:
 Simply creating a blank Axes and calling canvas.draw() leaks memory -- even 
 without displaying any data or shifting the x axes.

Okay, as a workaround have you tried ax.clear()?

So the example script provided by you can be boiled down further?

I'm using ax.clear() in a layered approach very extensively and have
never noticed memory leaks with this.  I'm having a Layer object which
can be fed by data, and when the data changes, it automatically will
trigger an ax.clear() in the host stack, and then everything is
redrawn.  Not the fastest, but fast enough.

Friedrich

--
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-12 Thread Russell Owen
I've boiled it down to nearly nothing as a script attached to this bug report:
https://sourceforge.net/tracker/?func=detailatid=560720aid=3124990group_id=80706
it simply creates an Axis and then regularly shifts the x axis limits and calls 
canvas.draw() to display the change. (It also reports memory usage.) You can 
further simplify the script by commenting out the limes that alter the x axis 
limits, but then the display does not change (though matplotlib still leaks 
memory as long as canvas.draw is still called).

I will try ax.clear(). Thanks.

-- Russell

On Dec 12, 2010, at 8:08 AM, Friedrich Romstedt wrote:

 2010/12/12 Russell Owen ro...@uw.edu:
 Simply creating a blank Axes and calling canvas.draw() leaks memory -- even 
 without displaying any data or shifting the x axes.
 
 Okay, as a workaround have you tried ax.clear()?
 
 So the example script provided by you can be boiled down further?
 
 I'm using ax.clear() in a layered approach very extensively and have
 never noticed memory leaks with this.  I'm having a Layer object which
 can be fed by data, and when the data changes, it automatically will
 trigger an ax.clear() in the host stack, and then everything is
 redrawn.  Not the fastest, but fast enough.
 
 Friedrich


--
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-11 Thread Friedrich Romstedt
2010/12/1 Russell E. Owen ro...@uw.edu:
 I'm seeing a nasty memory leak in my strip chart widget using matplotlib
 1.0, TkAgg and Mac OS X 10.5

 I've posted a minimal version here:
 http://www.astro.washington.edu/users/rowen/python/MinimalStripChartWdg.
 py

 It doesn't seem to matter if I use the animation API or not (the example
 does not).

 Any ideas?

Hmm, you're adding points right?  I remember one time I had a similar
timeline updating each second or so, and after 10 hr it took memory of
the order of Gigabytes (iirc) ... and it took seconds to refresh the
plot ... took me some time to figure it out that the plotting was the
culprit ...

hth, fwiw,
Friedrich

--
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-11 Thread Russell Owen
I am sort of adding data points; what I'm really doing is appending data to a 
python list and setting the data in the Line object to that list. The list gets 
shortened every once in awhile to keep the amount of data from getting too 
large.

It turns out the leak is in canvas.draw(), which I call whenever I shift the 
graph in time (by changing the limits on the x axis); if I don't call 
canvas.draw() the time shift is not displayed. Simply creating a blank Axes and 
calling canvas.draw() leaks memory -- even without displaying any data or 
shifting the x axes.

Regards,

-- Russell

On Dec 11, 2010, at 1:32 PM, Friedrich Romstedt wrote:

 2010/12/1 Russell E. Owen ro...@uw.edu:
 I'm seeing a nasty memory leak in my strip chart widget using matplotlib
 1.0, TkAgg and Mac OS X 10.5
 
 I've posted a minimal version here:
 http://www.astro.washington.edu/users/rowen/python/MinimalStripChartWdg.
 py
 
 It doesn't seem to matter if I use the animation API or not (the example
 does not).
 
 Any ideas?
 
 Hmm, you're adding points right?  I remember one time I had a similar
 timeline updating each second or so, and after 10 hr it took memory of
 the order of Gigabytes (iirc) ... and it took seconds to refresh the
 plot ... took me some time to figure it out that the plotting was the
 culprit ...
 
 hth, fwiw,
 Friedrich


--
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages, 
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory leak caused by canvas.draw()

2010-12-10 Thread Ryan May
On Thu, Dec 9, 2010 at 5:00 PM, Russell E. Owen ro...@uw.edu wrote:
 I explored the memory leak in my strip chart widget some more and found
 that it is caused by calling canvas.draw(), where canvas is:

 figure = matplotlib.figure.Figure(figsize=(8, 2), frameon=True)
 canvas = FigureCanvasTkAgg(figure, self)

 canvas.show() exhibits exactly the same problem.

 So...what is the right way to redraw a plot after its X axes have been
 changed?

draw() *is* the right way. It should definitely not be leaking.
Hopefully someone familiar with those kinds of problems can take a
look. (I just don't have the time right now.)

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

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


[Matplotlib-users] memory leak caused by canvas.draw()

2010-12-09 Thread Russell E. Owen
I explored the memory leak in my strip chart widget some more and found 
that it is caused by calling canvas.draw(), where canvas is:

figure = matplotlib.figure.Figure(figsize=(8, 2), frameon=True)
canvas = FigureCanvasTkAgg(figure, self)

canvas.show() exhibits exactly the same problem.

So...what is the right way to redraw a plot after its X axes have been 
changed?

-- Russell


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


[Matplotlib-users] Memory leak; user error or bug?

2010-12-01 Thread Russell E. Owen
I'm seeing a nasty memory leak in my strip chart widget using matplotlib 
1.0, TkAgg and Mac OS X 10.5

I've posted a minimal version here:
http://www.astro.washington.edu/users/rowen/python/MinimalStripChartWdg.
py

It doesn't seem to matter if I use the animation API or not (the example 
does not).

Any ideas? If this is a bug I'll report it, but I hope I'm just doing 
something wrong.

-- Russell


--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-01 Thread Michael Droettboom
On 12/01/2010 01:40 PM, Russell E. Owen wrote:
 I'm seeing a nasty memory leak in my strip chart widget using matplotlib
 1.0, TkAgg and Mac OS X 10.5

 I've posted a minimal version here:
 http://www.astro.washington.edu/users/rowen/python/MinimalStripChartWdg.
 py

 It doesn't seem to matter if I use the animation API or not (the example
 does not).

 Any ideas? If this is a bug I'll report it, but I hope I'm just doing
 something wrong.
I don't have a Mac to try this on -- however, I don't see the leak on 
Fedora 14/Python 2.7/Numpy 1.5.1/Tkinter with both matplotlib 1.0 and 
matplotlib SVN head.  That may narrow it down to something Mac OS 
X-specific.  Sorry that's not totally helpful, but it's a data point.

Mike

--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-01 Thread Russell E. Owen
In article 4cf69ba4.1000...@stsci.edu,
 Michael Droettboom md...@stsci.edu 
 wrote:

 On 12/01/2010 01:40 PM, Russell E. Owen wrote:
  I'm seeing a nasty memory leak in my strip chart widget using matplotlib
  1.0, TkAgg and Mac OS X 10.5
 
  I've posted a minimal version here:
  http://www.astro.washington.edu/users/rowen/python/MinimalStripChartWdg.
  py
 
  It doesn't seem to matter if I use the animation API or not (the example
  does not).
 
  Any ideas? If this is a bug I'll report it, but I hope I'm just doing
  something wrong.
 I don't have a Mac to try this on -- however, I don't see the leak on 
 Fedora 14/Python 2.7/Numpy 1.5.1/Tkinter with both matplotlib 1.0 and 
 matplotlib SVN head.  That may narrow it down to something Mac OS 
 X-specific.  Sorry that's not totally helpful, but it's a data point.

Thank you; that is very helpful. Unfortunately that suggests it is 
Mac-specific or Tcl/Tk-version-specific which could make it hard to 
track down. I'll report it as a bug in any case.

-- Russell


--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak; user error or bug?

2010-12-01 Thread Daniel Hyams
23 MB RPRVT @ 7:52 PM
40 MB RPRVT @ 8:07 PM

matplotlib 1.0.0
OSX 10.6.5
python.org python, 2.6.6


On Wed, Dec 1, 2010 at 6:53 PM, Russell E. Owen ro...@uw.edu wrote:

 In article 4cf69ba4.1000...@stsci.edu,
  Michael Droettboom md...@stsci.edu
  wrote:

  On 12/01/2010 01:40 PM, Russell E. Owen wrote:
   I'm seeing a nasty memory leak in my strip chart widget using
 matplotlib
   1.0, TkAgg and Mac OS X 10.5
  
   I've posted a minimal version here:
   
 http://www.astro.washington.edu/users/rowen/python/MinimalStripChartWdg.
   py
  
   It doesn't seem to matter if I use the animation API or not (the
 example
   does not).
  
   Any ideas? If this is a bug I'll report it, but I hope I'm just doing
   something wrong.
  I don't have a Mac to try this on -- however, I don't see the leak on
  Fedora 14/Python 2.7/Numpy 1.5.1/Tkinter with both matplotlib 1.0 and
  matplotlib SVN head.  That may narrow it down to something Mac OS
  X-specific.  Sorry that's not totally helpful, but it's a data point.

 Thank you; that is very helpful. Unfortunately that suggests it is
 Mac-specific or Tcl/Tk-version-specific which could make it hard to
 track down. I'll report it as a bug in any case.

 -- Russell



 --
 Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
 Tap into the largest installed PC base  get more eyes on your game by
 optimizing for Intel(R) Graphics Technology. Get started today with the
 Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
 http://p.sf.net/sfu/intelisp-dev2dev
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users




-- 
Daniel Hyams
dhy...@gmail.com
--
Increase Visibility of Your 3D Game App  Earn a Chance To Win $500!
Tap into the largest installed PC base  get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak

2010-03-01 Thread kwabena1

Hello 
I have encountered memory leak when using pylab.figure(), pylab.show(),
pylab.close(). I expected pylab.close() to flush the memory but this was not
the case. what am i doing wrong? Thanks in advance

Below is simple example
import os, sys, time
import gc
import matplotlib
matplotlib.use('TKAgg')
import pylab
import matplotlib.cbook as cbook

pid = os.getpid()
a2 = os.popen('ps -p %d -o vsz' % pid).readlines()
print 'memory before all figures the figure is drawn: ' + str(a2[1])

pylab.ion()
fig_list = []
for i in range(10):
fig_list.append(pylab.figure())
val = cbook.report_memory(i)
print i, val

pylab.show()
for fig in fig_list:
pylab.close(fig)

gc.collect()
print 'uncollectable list:', gc.garbage
a2 = os.popen('ps -p %d -o vsz' % pid).readlines()
print 'memory after all figures are closed : ' + str(a2[1])
**results**
memory before all figures the figure is drawn: 35424

0 4981
1 4981
2 5493
3 6005
4 6005
5 6517
6 6517
7 7029
8 7541
9 7541
uncollectable list: []
memory after all figures are closed : 80808
thanks
kwabena

-- 
View this message in context: 
http://old.nabble.com/Memory-leak-tp27741668p27741668.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
Download Intel#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] memory leak for GTKAgg animation

2010-02-15 Thread John Jameson
Hi John -
Yes thanks again!  This did it. Plus it is a valuable lesson
 - it never occurred to me to look at the base class to find 
more useful methods.  To make this cleaner I will post the
complete simple working example after this message.
best,
John  

-Original Message-
From: John Hunter [mailto:jdh2...@gmail.com] 
Sent: Sunday, February 14, 2010 7:39 PM
To: John Jameson
Cc: matplotlib-users@lists.sourceforge.net; Michael Droettboom
Subject: Re: [Matplotlib-users] memory leak for GTKAgg animation

On Sat, Feb 13, 2010 at 2:53 PM, John Jameson jjame...@altoresearch.com
wrote:
 HI,
 I find the very basic animation below has a memory leak (my pagefile usage
 number keeps growing in the Windows XP Windows Task Manager Performance
 graph).I don't see this with the animation_blit_gtk.py example on:

 http://matplotlib.sourceforge.net/examples/index.html

 (which I used as a starting point for this). In animation_blit_gtk.py
the
 set_ydata() routine is used to update the line for the animation and this
 does not leak. But if you call plot again with the new y_data (instead of
 using set_ydata), this leaks too. Anyone have an idea on how to stop the
 leak?

This isn't a memory leak.  The problem is that you keep adding new
patches to the axes when you want just one with different data.  Eg,
in your loop, run this code, and you will see that the number of
patches is growing:


   x_cir = 1.0 + 0.003*update_line.cnt
   cir =  CirclePolygon((x_cir, 1), 0.3, animated=True, \
   resolution=12, lw=2 )
   ax.add_patch(cir)
   ax.draw_artist(cir)
   print 'num patches=%d, mem usage=%d'%(
   len(ax.patches), cbook.report_memory(update_line.cnt))
   canvas.blit(ax.bbox)

You should add just one patch and then manipulate the data.  In this
case, you are using a CirclePolygon which derives from RegularPolygon
and so you can update the xy property

 
http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.Reg
ularPolygon

But on testing this it looks like there is a bug in that the set_xy
property setter is ignored.  I worked around this in the func below by
setting the private variable directly, but this looks like a bug we
need to fix (Michael, shouldn't we respect the xy passed in in
patches.RegularPolygon._set_xy ?).  In the meantime, the following
workaround should work for you w/o leaking

def update_line():
   global x, y
   print update_line.cnt
   if update_line.background is None:
   update_line.background = canvas.copy_from_bbox(ax.bbox)
   canvas.restore_region(update_line.background)

   x_cir = 1.0 + 0.003*update_line.cnt

   if update_line.cir is None:
   cir =  CirclePolygon((x_cir, 1), 0.3, animated=True, \
   resolution=12, lw=2 )
   ax.add_patch(cir)
   update_line.cir = cir
   else:
   update_line.cir._xy = x_cir, 1
   update_line.cir._update_transform()
   ax.draw_artist(update_line.cir)
   print 'num patches=%d, xy=%s, mem usage=%d'%(
   len(ax.patches), update_line.cir.xy,
cbook.report_memory(update_line.cnt))
   canvas.blit(ax.bbox)

   if update_line.direction == 0:
   update_line.cnt += 1
   if update_line.cnt  500:
   update_line.direction = 1
   else:
   update_line.cnt -= 1
   if update_line.cnt  100:
   update_line.direction = 0

   return update_line.cnt100


update_line.cnt = 0
update_line.direction = 0
update_line.background = None
update_line.cir = None



--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory leak for GTKAgg animation

2010-02-14 Thread John Hunter
On Sat, Feb 13, 2010 at 2:53 PM, John Jameson jjame...@altoresearch.com wrote:
 HI,
 I find the very basic animation below has a memory leak (my pagefile usage
 number keeps growing in the Windows XP Windows Task Manager Performance
 graph).I don't see this with the animation_blit_gtk.py example on:

 http://matplotlib.sourceforge.net/examples/index.html

 (which I used as a starting point for this). In animation_blit_gtk.py the
 set_ydata() routine is used to update the line for the animation and this
 does not leak. But if you call plot again with the new y_data (instead of
 using set_ydata), this leaks too. Anyone have an idea on how to stop the
 leak?

This isn't a memory leak.  The problem is that you keep adding new
patches to the axes when you want just one with different data.  Eg,
in your loop, run this code, and you will see that the number of
patches is growing:


   x_cir = 1.0 + 0.003*update_line.cnt
   cir =  CirclePolygon((x_cir, 1), 0.3, animated=True, \
   resolution=12, lw=2 )
   ax.add_patch(cir)
   ax.draw_artist(cir)
   print 'num patches=%d, mem usage=%d'%(
   len(ax.patches), cbook.report_memory(update_line.cnt))
   canvas.blit(ax.bbox)

You should add just one patch and then manipulate the data.  In this
case, you are using a CirclePolygon which derives from RegularPolygon
and so you can update the xy property

  
http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.RegularPolygon

But on testing this it looks like there is a bug in that the set_xy
property setter is ignored.  I worked around this in the func below by
setting the private variable directly, but this looks like a bug we
need to fix (Michael, shouldn't we respect the xy passed in in
patches.RegularPolygon._set_xy ?).  In the meantime, the following
workaround should work for you w/o leaking

def update_line():
   global x, y
   print update_line.cnt
   if update_line.background is None:
   update_line.background = canvas.copy_from_bbox(ax.bbox)
   canvas.restore_region(update_line.background)

   x_cir = 1.0 + 0.003*update_line.cnt

   if update_line.cir is None:
   cir =  CirclePolygon((x_cir, 1), 0.3, animated=True, \
   resolution=12, lw=2 )
   ax.add_patch(cir)
   update_line.cir = cir
   else:
   update_line.cir._xy = x_cir, 1
   update_line.cir._update_transform()
   ax.draw_artist(update_line.cir)
   print 'num patches=%d, xy=%s, mem usage=%d'%(
   len(ax.patches), update_line.cir.xy,
cbook.report_memory(update_line.cnt))
   canvas.blit(ax.bbox)

   if update_line.direction == 0:
   update_line.cnt += 1
   if update_line.cnt  500:
   update_line.direction = 1
   else:
   update_line.cnt -= 1
   if update_line.cnt  100:
   update_line.direction = 0

   return update_line.cnt100


update_line.cnt = 0
update_line.direction = 0
update_line.background = None
update_line.cir = None

--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] memory leak for GTKAgg animation

2010-02-13 Thread John Jameson
HI,
I find the very basic animation below has a memory leak (my pagefile usage
number keeps growing in the Windows XP Windows Task Manager Performance
graph).I don't see this with the animation_blit_gtk.py example on:

http://matplotlib.sourceforge.net/examples/index.html

(which I used as a starting point for this). In animation_blit_gtk.py the
set_ydata() routine is used to update the line for the animation and this
does not leak. But if you call plot again with the new y_data (instead of
using set_ydata), this leaks too. Anyone have an idea on how to stop the
leak? 

thanks,
john




import gtk, gobject
import matplotlib
matplotlib.use('GTKAgg') 
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from matplotlib.patches import CirclePolygon

fig = plt.figure(figsize=(10,6))
ax = fig.add_subplot(111, autoscale_on=False )
canvas = fig.canvas

plt.axis([-1, 7, -0.5, 2.2])


def update_line():
global x, y
print update_line.cnt
if update_line.background is None:
update_line.background = canvas.copy_from_bbox(ax.bbox)
canvas.restore_region(update_line.background)

x_cir = 1.0 + 0.003*update_line.cnt 
cir =  CirclePolygon((x_cir, 1), 0.3, animated=True, \
resolution=12, lw=2 )
ax.add_patch(cir)
ax.draw_artist(cir)

canvas.blit(ax.bbox)

if update_line.direction == 0:
update_line.cnt += 1
if update_line.cnt  500:
update_line.direction = 1
else:
update_line.cnt -= 1
if update_line.cnt  100:
update_line.direction = 0

return True



update_line.cnt = 0
update_line.direction = 0
update_line.background = None

def start_anim(event):
gobject.idle_add(update_line)
canvas.mpl_disconnect(start_anim.cid)

start_anim.cid = canvas.mpl_connect('draw_event', start_anim)

plt.show()



--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak when destroying Tk frame containing a figure

2010-02-12 Thread Stephan Markus
Calling the garbage collector (gc.collect()) also makes no difference.
Even deleting all references manually and dropping the toolbar code
doesn't do the trick.


Am 09.02.2010 16:19, schrieb Stephan Markus:
 I already had my destroy() method look like this:

 def destroy(self):
 self.f.clf()
 Tix.Frame.destroy(self)
 self.toolbar.destroy()
 self.canvas._tkcanvas.destroy()


 But it makes no difference.

 Stephan

 Am 08.02.2010 17:15, schrieb Michael Droettboom:
   
 Have you tried explicitly calling .clf() on the matplotlib Figure object 
 from your Tix.Frame.destroy callback?

 Mike

   
 


--
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak when destroying Tk frame containing a figure

2010-02-09 Thread Stephan Markus
I already had my destroy() method look like this:

def destroy(self):
self.f.clf()
Tix.Frame.destroy(self)
self.toolbar.destroy()
self.canvas._tkcanvas.destroy()


But it makes no difference.

Stephan

Am 08.02.2010 17:15, schrieb Michael Droettboom:
 Have you tried explicitly calling .clf() on the matplotlib Figure object from 
 your Tix.Frame.destroy callback?

 Mike

   

--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak when destroying Tk frame containing a figure

2010-02-08 Thread Maximilian Mauer
Hello! I'm writing an application that will show different plots on it's GUI. In order to switch between the different plot types I'd like to destroy the first plot and to create a new afterwards. I stumbled into a memory leak since I don't know how to close matplotlib figures the clean way. I wrote a small test programm. Pressing the button 'create' creates a figure and 'delete' should destroy it. Since the graph class is derived from the Tix.Frame class I would expect that destroying the Frame would also remove all matplot stuff. But when I do not implement my own destroy() method in the graph class, destroying the Frame shows absolutely no effect. The plot simply stays on the screen. When I overload the Tix.Frame.destroy() method with my own implementation, as shown below, the plot disappears but not all memory is being released. When creating and deleting figures, the amount of memory python needs is constantly growing and python eventually crashes. I tried to find a solution on the internet but I found nothing really helpful so far. All examples I found just display something and then just exit. I appreciate any help! -- import matplotlib matplotlib.use('TkAgg') from numpy import arange, sin, pi from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg from matplotlib.figure import Figure import Tix  import sys def destroy(e): sys.exit() root = Tix.Tk() class graph(Tix.Frame):   def __init__(self, master, **kw): Tix.Frame.__init__(self, master, **kw) self.f = Figure(figsize=(5,4), dpi=100) self.a = self.f.add_subplot(111) t = arange(0.0,3.0,0.01) s = sin(2*pi*t) self.a.plot(t,s) self.canvas = FigureCanvasTkAgg(self.f, master=self.master) self.canvas.show() self.canvas.get_tk_widget().pack(side=Tix.TOP, fill=Tix.BOTH, expand=1) self.toolbar = NavigationToolbar2TkAgg(self.canvas, root ) self.toolbar.update() self.canvas._tkcanvas.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)def destroy(self): Tix.Frame.destroy(self) self.toolbar.destroy() self.canvas._tkcanvas.destroy()   class ui(Tix.Frame):  g = None  def __init__(self, master, **kw): Tix.Frame.__init__(self, master, **kw)  self.b = Tix.Button(self, text='create', command=self.create) self.b.pack()  self.b2 = Tix.Button(self, text='delete', command=self.delete) self.b2.pack()   def delete(self): try:   self.g.destroy() except:   passdef create(self): self.delete() self.g = graph(root)ui(root).pack() root.mainloop()GRATIS fr alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!Jetzt freischalten unter http://movieflat.web.de


--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak when destroying Tk frame containing a figure

2010-02-08 Thread Michael Droettboom
Have you tried explicitly calling .clf() on the matplotlib Figure object from 
your Tix.Frame.destroy callback?

Mike

--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak when destroying Tk frame containing a figure

2010-02-04 Thread Stephan Markus

Hello!

I'm writing an application that will show different plots on it's GUI. In
order to switch between the different plot types I'd like to destroy the
first plot and to create a new afterwards. I stumbled into a memory leak
since I don't know how to close matplotlib figures the clean way.

I wrote a small test programm. Pressing the button 'create' creates a figure
and 'delete' should destroy it.
Since the graph class is derived from the Tix.Frame class I would expect
that destroying the Frame would also remove all matplot stuff. But when I do
not implement my own destroy() method in the graph class, destroying the
Frame shows absolutely no effect. The plot simply stays on the screen. 
When I overload the Tix.Frame.destroy() method with my own implementation,
as shown below, the plot disappears but not all memory is being released.
When creating and deleting figures, the amount of memory python needs is
constantly growing and python eventually crashes.

I tried to find a solution on the internet but I found nothing really
helpful so far. All examples I found just display something and then just
exit.

I appreciate any help!

--

import matplotlib
matplotlib.use('TkAgg')

from numpy import arange, sin, pi
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg,
NavigationToolbar2TkAgg
from matplotlib.figure import Figure


import Tix 
import sys

def destroy(e): sys.exit()

root = Tix.Tk()


class graph(Tix.Frame):
def __init__(self, master, **kw):
Tix.Frame.__init__(self, master, **kw)

self.f = Figure(figsize=(5,4), dpi=100)
self.a = self.f.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
self.a.plot(t,s)

self.canvas = FigureCanvasTkAgg(self.f, master=self.master)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=Tix.TOP, fill=Tix.BOTH,
expand=1)

self.toolbar = NavigationToolbar2TkAgg(self.canvas, root )
self.toolbar.update()
self.canvas._tkcanvas.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)

def destroy(self):
Tix.Frame.destroy(self)
self.toolbar.destroy()
self.canvas._tkcanvas.destroy()


class ui(Tix.Frame):

g = None

def __init__(self, master, **kw):
Tix.Frame.__init__(self, master, **kw)

self.b = Tix.Button(self, text='create', command=self.create)
self.b.pack()

self.b2 = Tix.Button(self, text='delete', command=self.delete)
self.b2.pack()

def delete(self):
try:
self.g.destroy()
except:
pass

def create(self):
self.delete()
self.g = graph(root)

   
ui(root).pack()
root.mainloop()

-- 
View this message in context: 
http://old.nabble.com/Memory-leak-when-destroying-Tk-frame-containing-a-figure-tp27452209p27452209.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


--
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak in pcolor?

2009-10-23 Thread Teemu Ikonen
Hi all,

Typing this (on ipython prompt with the relevant libraries imported)

x = linspace(0,1.0,500)
y = linspace(0,1.0,500)
xg,yg = meshgrid(x,y)
c = rand(len(x), len(y))
pcolor(xg,yg,c)

Makes the ipython process to grow to have about 400 Mb of resident
memory and it takes ages for the plot to appear (a 1000x1000 image
just makes my 1 Gb system trash helplessly).

But, using pcolormesh instead of pcolor in the last line of the script
above works ok, the plot appears almost immediately, and the memory
consumption of the ipython process only doubles, i.e. grows about 30
Mb.

Is this a bug or am I doing something wrong? I'm using
python-matplotlib 0.99.0-1 from Debian.

Best,

Teemu

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in pcolor?

2009-10-23 Thread Eric Firing
Teemu Ikonen wrote:
 Hi all,
 
 Typing this (on ipython prompt with the relevant libraries imported)
 
 x = linspace(0,1.0,500)
 y = linspace(0,1.0,500)
 xg,yg = meshgrid(x,y)
 c = rand(len(x), len(y))
 pcolor(xg,yg,c)
 
 Makes the ipython process to grow to have about 400 Mb of resident
 memory and it takes ages for the plot to appear (a 1000x1000 image
 just makes my 1 Gb system trash helplessly).
 
 But, using pcolormesh instead of pcolor in the last line of the script
 above works ok, the plot appears almost immediately, and the memory
 consumption of the ipython process only doubles, i.e. grows about 30
 Mb.
 
 Is this a bug or am I doing something wrong? I'm using
 python-matplotlib 0.99.0-1 from Debian.

It is a limitation of pcolor, which uses a PolyCollection--very flexible 
and general, but very inefficient for simple cases with many polygons. 
With a regular grid, you can simply use an image, for the highest 
performance.  pcolormesh is also a good alternative, and more general 
than image.  There is no pyplot wrapper, but the Axes.pcolorfast method 
can use any of three different algorithms to achieve pcolor-like results 
with the highest possible efficiency for a given grid.

Eric
 
 Best,
 
 Teemu
 
 --
 Come build with us! The BlackBerry(R) Developer Conference in SF, CA
 is the only developer event you need to attend this year. Jumpstart your
 developing skills, take BlackBerry mobile applications to market and stay 
 ahead of the curve. Join us from November 9 - 12, 2009. Register now!
 http://p.sf.net/sfu/devconference
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak somewhere?

2009-08-25 Thread pixolex pixolex
You made my day!

Long life to The close()

All my ram and swap file was sucked every time a run my script to generate
260 png images...almost killing my ubuntu!

On Tue, May 26, 2009 at 2:23 PM, John Hunter jdh2...@gmail.com wrote:

 On Tue, May 26, 2009 at 7:39 AM, Michael Droettboom md...@stsci.edu
 wrote:
  Does it help if you add a call to plt.clf() to the bottom of the loop?
 
  The pyplot interface keeps a reference around to every figure created
  until they are destroyed so that it can be obtained again by number
  (this is functionality inspired by matlab).  Alternatively, you can use
  the object-oriented interface to create the figure, which does not have
  this behavior, e.g., replace
 
fig = plt.figure()
 
  with
 
from matplotlib import figure
fig = figure.Figure()
 
  If all this doesn't help, let me know and I'll look further.
 
  Cheers,
  Mike
 
  iCy-fLaME wrote:
  I was trying to use matplotlib to plot a series of 2D images, but
  python was using up a large amount of RAM very quickly. I don't know
  matplotlib that well, so the chance are I am missing something, would
  appreciate it if anyone can point me to the right direction.
 
  I am using:
  Python 2.4.3 (#1, Jan 21 2009, 01:11:33)
  [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
 
  Example code to run in interpreter mode:
 
  
  from numpy import zeros
 
  x = 1651
  y = 452
  page = zeros((x, y)).astype('float')
 
  import matplotlib
  matplotlib.use('Agg')
  import matplotlib.pyplot as plt
 
  for i in range(1000):
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.imshow(page, cmap=plt.cm.spectral_r, extent=(-44, 176,
 -30,
  30), interpolation = 'bicubic', vmin = -0.003, vmax = 0.003)
title = Time = %(i)0.3es) % {'i':i}
ax.set_title(title,fontsize=14)
 
fig.colorbar(cax, ticks=[-2e-3, -1e-3, 0, 1e-3, 2e-3],
  orientation='horizontal')
 
fig.savefig('_tmp.' + str(i) + .png, dpi=300)


 This code creates 1000 different figures -- either reuse the same
 figure and clear it as Michael suggests

  fig = plt.figure(1)  # by putting 1 here you reuse the same fig
  fig.clf()  # and clear it

 or close the figure in the loop

  fig = plt.figure()
  # draw and save here
  plt.close(fig)

 JDH


 --
 Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
 is a gathering of tech-side developers  brand creativity professionals.
 Meet
 the minds behind Google Creative Lab, Visual Complexity, Processing, 
 iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
 Group, R/GA,  Big Spaceship. http://www.creativitycat.com
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory leak with PyQt4 plus savefig or print_figure

2009-07-22 Thread Alexander Baker


Ralph,

Perhaps time to migrate to Chaco API from Enthought? not sure if there is
Ubuntu support yet however.

Alex Baker

http://code.enthought.com/chaco/


Ralf Gommers-2 wrote:
 
 Hi,
 
 I am working on a PyQt4 application with some embedded MPL figures, and am
 also trying to save some figures as png's without displaying them. I am
 observing huge memory increases (10s or 100s of Mb) the moment I try to
 save
 a png. I reproduced the issue by combining two mpl examples,
 http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.htmland
 http://matplotlib.sourceforge.net/examples/api/agg_oo.html. Full code is
 attached. When pressing the save figure button, memory usage shoots up,
 multiple clicks keep sending it higher (although not monotonically).
 
 I tested on two different platforms
 - Matplotlib 98.5.2 and Python 2.6.2 on Ubuntu.
 - latest Enthought Python Distribution on Windows XP.
 
 The function that does the png saving is:
 
 def save_png():
 Save an image as a png file
 
 pngpath = 'test_mplsave.png'
 
 fig = Figure()
 canvas = FigureCanvas(fig)
 ax = fig.add_subplot(111)
 x = arange(5e3)
 ax.plot(x, sin(x))
 canvas.print_figure(pngpath)
 
 ## tried all things commented out below, all makes no difference ##
 #fig.savefig(pngpath)
 
 #del(fig)
 #del(canvas)
 #del(ax)
 
 #import matplotlib.pyplot as plt
 #plt.close(fig)
 
 #import gc
 #gc.collect()
 
 Commenting out the canvas.print_figure line fixes the issue.
 
 Am I doing something obviously wrong, or mixing two incompatible ways of
 doing things?
 
 Cheers,
 Ralf
 
 #!/usr/bin/env python
 
 # embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib
 canvases
 #
 # Copyright (C) 2005 Florent Rougon
 #   2006 Darren Dale
 #
 # This file is an example program for matplotlib. It may be used and
 # modified with no restriction; raw copies as well as modified versions
 # may be distributed without limitation.
 
 import sys, os, random
 from PyQt4 import QtGui, QtCore
 
 from numpy import arange, sin, pi
 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
 FigureCanvas
 from matplotlib.figure import Figure
 
 
 class MyMplCanvas(FigureCanvas):
 Ultimately, this is a QWidget (as well as a FigureCanvasAgg,
 etc.).
 def __init__(self, parent=None, width=5, height=4, dpi=100):
 fig = Figure(figsize=(width, height), dpi=dpi)
 self.axes = fig.add_subplot(111)
 # We want the axes cleared every time plot() is called
 self.axes.hold(False)
 
 self.compute_initial_figure()
 
 FigureCanvas.__init__(self, fig)
 self.setParent(parent)
 
 FigureCanvas.setSizePolicy(self,
QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
 FigureCanvas.updateGeometry(self)
 
 def compute_initial_figure(self):
 pass
 
 
 class MyStaticMplCanvas(MyMplCanvas):
 Simple canvas with a sine plot.
 def compute_initial_figure(self):
 t = arange(0.0, 3.0, 0.01)
 s = sin(2*pi*t)
 self.axes.plot(t, s)
 
 
 def save_png():
 Save an image as a png file
 
 pngpath = 'test_mplsave.png'
 
 fig = Figure()
 canvas = FigureCanvas(fig)
 ax = fig.add_subplot(111)
 x = arange(5e3)
 ax.plot(x, sin(x))
 #canvas.print_figure(pngpath)
 
 ## tried all things commented out below, all makes no difference ##
 #fig.savefig(pngpath)
 
 #del(fig)
 #del(canvas)
 #del(ax)
 
 #import matplotlib.pyplot as plt
 #plt.close(fig)
 
 #import gc
 #gc.collect()
 
 
 class ApplicationWindow(QtGui.QMainWindow):
 def __init__(self):
 QtGui.QMainWindow.__init__(self)
 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
 self.setWindowTitle(application main window)
 
 self.file_menu = QtGui.QMenu('File', self)
 self.file_menu.addAction('Quit', self.fileQuit,
  QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
 self.menuBar().addMenu(self.file_menu)
 
 self.help_menu = QtGui.QMenu('Help', self)
 
 self.main_widget = QtGui.QWidget(self)
 
 l = QtGui.QVBoxLayout(self.main_widget)
 sc = MyStaticMplCanvas(self.main_widget, width=5, height=4,
 dpi=100)
 dc = QtGui.QPushButton('Save image')
 l.addWidget(sc)
 l.addWidget(dc)
 
 self.main_widget.setFocus()
 self.setCentralWidget(self.main_widget)
 
 self.statusBar().showMessage(All hail matplotlib!, 2000)
 self.connect(dc, QtCore.SIGNAL(clicked()), save_png)
 
 def fileQuit(self):
 self.close()
 
 def closeEvent(self, ce):
 self.fileQuit()
 
 
 qApp = QtGui.QApplication(sys.argv)
 
 aw = ApplicationWindow()
 aw.setWindowTitle(Try saving a simple png image)
 aw.show()
 sys.exit(qApp.exec_())
 
 

Re: [Matplotlib-users] memory leak with PyQt4 plus savefig or print_figure

2009-07-02 Thread Ralf Gommers
sorry, i replied to Mike and not to the list. see below.


On Thu, Jul 2, 2009 at 2:57 PM, Ralf Gommers ralf.gomm...@googlemail.comwrote:

 Thanks for looking into this Mike.

 On Thu, Jul 2, 2009 at 10:39 AM, Michael Droettboom md...@stsci.eduwrote:

 It is not surprising that memory usage is much lower without printing the
 plot.  Very little is actually done by the plot command other than setting
 up a tree of objects that is later rendered during the printing process
 (where most of the work happens).

 The attached script based on what you provided doesn't leak memory for me
 with matplotlib 0.98.5.2.  It would appear that there is something else in
 your application triggering the leak.  Perhaps there is something holding a
 reference longer than it should?


 Your attached script memleak2.py is indeed fine, it never takes up more
 than 60Mb of RAM. But did you try to run the PyQt4  GUI I attached? There
 the same save_png() function does increase memory usage for each call.

 I'm not sure how to exactly measure memory usage for a GUI program, but it
 is so large I can look at System Activity (or Task Manager on XP) and get
 the approximate number:

 Loading the GUI: 30.5Mb
 1st call to save_png: 82Mb
 2nd call: 116Mb
 10th call: 380Mb

 I can see the memory usage drop after some calls, so I guess it is a
 problem of references being held and sometimes being released as you said.
 But memory use does seem to be unbounded. Waiting for minutes, or
 interacting with the GUI, never releases any memory. It is strange, the
 PyQt4 demo program is fine by itself, save_png() is fine by itself, but
 combine them and there's a memory problem.

 Cheers,
 Ralf



 You can see from the attached massif plots that memory usage never becomes
 unbounded.  It is normal for Python to delay deallocation for efficiency
 reasons.  Calling gc.collect (the second graph) does help keep memory usage
 more compact however, if that is a primary concern.

 Cheers,
 Mike

 Ralf Gommers wrote:

 Hi,

 I am working on a PyQt4 application with some embedded MPL figures, and
 am also trying to save some figures as png's without displaying them. I am
 observing huge memory increases (10s or 100s of Mb) the moment I try to save
 a png. I reproduced the issue by combining two mpl examples,
 http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.htmland
 http://matplotlib.sourceforge.net/examples/api/agg_oo.html. Full code is
 attached. When pressing the save figure button, memory usage shoots up,
 multiple clicks keep sending it higher (although not monotonically).

 I tested on two different platforms
 - Matplotlib 98.5.2 and Python 2.6.2 on Ubuntu.
 - latest Enthought Python Distribution on Windows XP.

 The function that does the png saving is:

 def save_png():
Save an image as a png file

pngpath = 'test_mplsave.png'

fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
x = arange(5e3)
ax.plot(x, sin(x))
canvas.print_figure(pngpath)

## tried all things commented out below, all makes no difference ##
#fig.savefig(pngpath)

#del(fig)
#del(canvas)
#del(ax)

#import matplotlib.pyplot as plt
#plt.close(fig)

#import gc
#gc.collect()

 Commenting out the canvas.print_figure line fixes the issue.

 Am I doing something obviously wrong, or mixing two incompatible ways of
 doing things?

 Cheers,
 Ralf

 


 --
 

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


 --
 Michael Droettboom
 Science Software Branch
 Operations and Engineering Division
 Space Telescope Science Institute
 Operated by AURA for NASA


 from matplotlib.backends.backend_agg import FigureCanvasAgg as
 FigureCanvas
 from matplotlib.figure import Figure

 from numpy import arange, sin

 import gc

 def save_png():
Save an image as a png file

pngpath = 'test_mplsave.png'

fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
x = arange(5e3)
ax.plot(x, sin(x))
canvas.print_figure(pngpath)

# The below is not necessary to prevent a leak, but it does make
# memory usage more compact
gc.collect()

 for i in range(100):
save_png()





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


[Matplotlib-users] memory leak with PyQt4 plus savefig or print_figure

2009-07-01 Thread Ralf Gommers
Hi,

I am working on a PyQt4 application with some embedded MPL figures, and am
also trying to save some figures as png's without displaying them. I am
observing huge memory increases (10s or 100s of Mb) the moment I try to save
a png. I reproduced the issue by combining two mpl examples,
http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_qt4.htmland
http://matplotlib.sourceforge.net/examples/api/agg_oo.html. Full code is
attached. When pressing the save figure button, memory usage shoots up,
multiple clicks keep sending it higher (although not monotonically).

I tested on two different platforms
- Matplotlib 98.5.2 and Python 2.6.2 on Ubuntu.
- latest Enthought Python Distribution on Windows XP.

The function that does the png saving is:

def save_png():
Save an image as a png file

pngpath = 'test_mplsave.png'

fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
x = arange(5e3)
ax.plot(x, sin(x))
canvas.print_figure(pngpath)

## tried all things commented out below, all makes no difference ##
#fig.savefig(pngpath)

#del(fig)
#del(canvas)
#del(ax)

#import matplotlib.pyplot as plt
#plt.close(fig)

#import gc
#gc.collect()

Commenting out the canvas.print_figure line fixes the issue.

Am I doing something obviously wrong, or mixing two incompatible ways of
doing things?

Cheers,
Ralf
#!/usr/bin/env python

# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
#   2006 Darren Dale
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.

import sys, os, random
from PyQt4 import QtGui, QtCore

from numpy import arange, sin, pi
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure


class MyMplCanvas(FigureCanvas):
Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

FigureCanvas.__init__(self, fig)
self.setParent(parent)

FigureCanvas.setSizePolicy(self,
   QtGui.QSizePolicy.Expanding,
   QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)

def compute_initial_figure(self):
pass


class MyStaticMplCanvas(MyMplCanvas):
Simple canvas with a sine plot.
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)


def save_png():
Save an image as a png file

pngpath = 'test_mplsave.png'

fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
x = arange(5e3)
ax.plot(x, sin(x))
#canvas.print_figure(pngpath)

## tried all things commented out below, all makes no difference ##
#fig.savefig(pngpath)

#del(fig)
#del(canvas)
#del(ax)

#import matplotlib.pyplot as plt
#plt.close(fig)

#import gc
#gc.collect()


class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle(application main window)

self.file_menu = QtGui.QMenu('File', self)
self.file_menu.addAction('Quit', self.fileQuit,
 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)

self.help_menu = QtGui.QMenu('Help', self)

self.main_widget = QtGui.QWidget(self)

l = QtGui.QVBoxLayout(self.main_widget)
sc = MyStaticMplCanvas(self.main_widget, width=5, height=4, dpi=100)
dc = QtGui.QPushButton('Save image')
l.addWidget(sc)
l.addWidget(dc)

self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)

self.statusBar().showMessage(All hail matplotlib!, 2000)
self.connect(dc, QtCore.SIGNAL(clicked()), save_png)

def fileQuit(self):
self.close()

def closeEvent(self, ce):
self.fileQuit()


qApp = QtGui.QApplication(sys.argv)

aw = ApplicationWindow()
aw.setWindowTitle(Try saving a simple png image)
aw.show()
sys.exit(qApp.exec_())
--
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak somewhere?

2009-05-26 Thread iCy-fLaME
I was trying to use matplotlib to plot a series of 2D images, but
python was using up a large amount of RAM very quickly. I don't know
matplotlib that well, so the chance are I am missing something, would
appreciate it if anyone can point me to the right direction.

I am using:
Python 2.4.3 (#1, Jan 21 2009, 01:11:33)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2

Example code to run in interpreter mode:


from numpy import zeros

x = 1651
y = 452
page = zeros((x, y)).astype('float')

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt

for i in range(1000):
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.imshow(page, cmap=plt.cm.spectral_r, extent=(-44, 176, -30,
30), interpolation = 'bicubic', vmin = -0.003, vmax = 0.003)
title = Time = %(i)0.3es) % {'i':i}
ax.set_title(title,fontsize=14)

fig.colorbar(cax, ticks=[-2e-3, -1e-3, 0, 1e-3, 2e-3],
orientation='horizontal')

fig.savefig('_tmp.' + str(i) + .png, dpi=300)

### EOF 


I tired to delete everything in the namespace, but the only way I can
release the ram is by killing the python session.



Thanks for all the helps in advance.



iCy

--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA,  Big Spaceship. http://www.creativitycat.com 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak somewhere?

2009-05-26 Thread Michael Droettboom
Does it help if you add a call to plt.clf() to the bottom of the loop?

The pyplot interface keeps a reference around to every figure created 
until they are destroyed so that it can be obtained again by number 
(this is functionality inspired by matlab).  Alternatively, you can use 
the object-oriented interface to create the figure, which does not have 
this behavior, e.g., replace

   fig = plt.figure()

with

   from matplotlib import figure
   fig = figure.Figure()

If all this doesn't help, let me know and I'll look further.

Cheers,
Mike

iCy-fLaME wrote:
 I was trying to use matplotlib to plot a series of 2D images, but
 python was using up a large amount of RAM very quickly. I don't know
 matplotlib that well, so the chance are I am missing something, would
 appreciate it if anyone can point me to the right direction.

 I am using:
 Python 2.4.3 (#1, Jan 21 2009, 01:11:33)
 [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2

 Example code to run in interpreter mode:

 
 from numpy import zeros

 x = 1651
 y = 452
 page = zeros((x, y)).astype('float')

 import matplotlib
 matplotlib.use('Agg')
 import matplotlib.pyplot as plt

 for i in range(1000):
   fig = plt.figure()
   ax = fig.add_subplot(111)
   cax = ax.imshow(page, cmap=plt.cm.spectral_r, extent=(-44, 176, -30,
 30), interpolation = 'bicubic', vmin = -0.003, vmax = 0.003)
   title = Time = %(i)0.3es) % {'i':i}
   ax.set_title(title,fontsize=14)
   
   fig.colorbar(cax, ticks=[-2e-3, -1e-3, 0, 1e-3, 2e-3],
 orientation='horizontal')
   
   fig.savefig('_tmp.' + str(i) + .png, dpi=300)
   
 ### EOF 


 I tired to delete everything in the namespace, but the only way I can
 release the ram is by killing the python session.



 Thanks for all the helps in advance.



 iCy

 --
 Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
 is a gathering of tech-side developers  brand creativity professionals. Meet
 the minds behind Google Creative Lab, Visual Complexity, Processing,  
 iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
 Group, R/GA,  Big Spaceship. http://www.creativitycat.com 
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA,  Big Spaceship. http://www.creativitycat.com 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak somewhere?

2009-05-26 Thread John Hunter
On Tue, May 26, 2009 at 7:39 AM, Michael Droettboom md...@stsci.edu wrote:
 Does it help if you add a call to plt.clf() to the bottom of the loop?

 The pyplot interface keeps a reference around to every figure created
 until they are destroyed so that it can be obtained again by number
 (this is functionality inspired by matlab).  Alternatively, you can use
 the object-oriented interface to create the figure, which does not have
 this behavior, e.g., replace

   fig = plt.figure()

 with

   from matplotlib import figure
   fig = figure.Figure()

 If all this doesn't help, let me know and I'll look further.

 Cheers,
 Mike

 iCy-fLaME wrote:
 I was trying to use matplotlib to plot a series of 2D images, but
 python was using up a large amount of RAM very quickly. I don't know
 matplotlib that well, so the chance are I am missing something, would
 appreciate it if anyone can point me to the right direction.

 I am using:
 Python 2.4.3 (#1, Jan 21 2009, 01:11:33)
 [GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2

 Example code to run in interpreter mode:

 
 from numpy import zeros

 x = 1651
 y = 452
 page = zeros((x, y)).astype('float')

 import matplotlib
 matplotlib.use('Agg')
 import matplotlib.pyplot as plt

 for i in range(1000):
   fig = plt.figure()
   ax = fig.add_subplot(111)
   cax = ax.imshow(page, cmap=plt.cm.spectral_r, extent=(-44, 176, -30,
 30), interpolation = 'bicubic', vmin = -0.003, vmax = 0.003)
   title = Time = %(i)0.3es) % {'i':i}
   ax.set_title(title,fontsize=14)

   fig.colorbar(cax, ticks=[-2e-3, -1e-3, 0, 1e-3, 2e-3],
 orientation='horizontal')

   fig.savefig('_tmp.' + str(i) + .png, dpi=300)


This code creates 1000 different figures -- either reuse the same
figure and clear it as Michael suggests

  fig = plt.figure(1)  # by putting 1 here you reuse the same fig
  fig.clf()  # and clear it

or close the figure in the loop

  fig = plt.figure()
  # draw and save here
  plt.close(fig)

JDH

--
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers  brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing,  
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA,  Big Spaceship. http://www.creativitycat.com 
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in Agg backend?

2009-04-22 Thread Jesper Larsen
Hi Michael and others,

Sorry for the late answer. I am on Ubuntu 8.10. Unfortunately I have
not had time to look any more into the issue (which might very well be
an error on my part) but I will return when I have more info (I have
made a temporary fix).

I tried using valgrind-massif to reproduce your plot but unfortunately
newer versions of valgrind-massif do not support ps plots.

Best regards,
Jesper

2009/4/15 Michael Droettboom md...@stsci.edu:
 I am not able to reproduce this leak here with 0.98.6svn from today on
 RHEL4.  What platform are you on?

 (See attached massif profile -- the memory usage is flat...)

 Mike

 Jesper Larsen wrote:

 Hi matplotlib developers and users,

 I have had some problems with a memory leak in a long running
 matplotlib based web application that I have developed
 (www.worldwildweather.com). I believe the problem is due to a memory
 leak in the Agg backend but I am not sure. Below is a script which for
 me results in a consistently increasing amount of  memory usage. I am
 using mpl version 0.98.6svn. The problem does not occur when the
 savefig command is commented out. And it does not occur when cs =
 ax.contourf(z) and ax.cla() are moved outside the loop (before and
 after respectively).

 Best regards,
 Jesper

 import os, gc
 import numpy as npy
 import matplotlib as mpl
 from matplotlib.figure import Figure
 from matplotlib.backends.backend_agg import FigureCanvasAgg as
 FigureCanvas

 def report_memory():
    Report memory.
    gc.collect()
    pid = os.getpid()
    a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
    return int(a2[1].split()[1])

 fig = Figure(dpi=100)
 ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
 FigureCanvas(fig)

 n = 1000
 z = npy.zeros((n,n))
 for i in range(2000):
    cs = ax.contourf(z)
    fig.savefig('test.png')
    ax.cla()
    print report_memory(), i

 I have not pasted in all of the output but just the first and last 25
 lines:
 53356 0
 53360 1
 53360 2
 53360 3
 53360 4
 53360 5
 53360 6
 53360 7
 53360 8
 53360 9
 53360 10
 53360 11
 53360 12
 53360 13
 53360 14
 53360 15
 53360 16
 53360 17
 53356 18
 53360 19
 53360 20
 53360 21
 53360 22
 53360 23
 53356 24
 ...
 57552 1975
 57552 1976
 57552 1977
 57552 1978
 57552 1979
 57552 1980
 57552 1981
 57552 1982
 57552 1983
 57552 1984
 57552 1985
 57552 1986
 57552 1987
 57552 1988
 57552 1989
 57552 1990
 57552 1991
 57552 1992
 57552 1993
 57552 1994
 57552 1995
 57552 1996
 57552 1997
 57552 1998
 57552 1999


 --
 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


 --
 Michael Droettboom
 Science Software Branch
 Operations and Engineering Division
 Space Telescope Science Institute
 Operated by AURA for NASA



--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in Agg backend?

2009-04-17 Thread Andres Luhamaa
Michael Droettboom wrote:
 I am not able to reproduce this leak here with 0.98.6svn from today on 
 RHEL4.  What platform are you on?

 (See attached massif profile -- the memory usage is flat...)

 Mike
Well, in my setup I see similar behaviour as in the initial question. 
Ubuntu 8.10 32bit, 2-days old svn verion of matplotlib.

Andres

 Jesper Larsen wrote:
 Hi matplotlib developers and users,

 I have had some problems with a memory leak in a long running
 matplotlib based web application that I have developed
 (www.worldwildweather.com). I believe the problem is due to a memory
 leak in the Agg backend but I am not sure. Below is a script which for
 me results in a consistently increasing amount of  memory usage. I am
 using mpl version 0.98.6svn. The problem does not occur when the
 savefig command is commented out. And it does not occur when cs =
 ax.contourf(z) and ax.cla() are moved outside the loop (before and
 after respectively).

 Best regards,
 Jesper

 import os, gc
 import numpy as npy
 import matplotlib as mpl
 from matplotlib.figure import Figure
 from matplotlib.backends.backend_agg import FigureCanvasAgg as 
 FigureCanvas

 def report_memory():
 Report memory.
 gc.collect()
 pid = os.getpid()
 a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
 return int(a2[1].split()[1])

 fig = Figure(dpi=100)
 ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
 FigureCanvas(fig)

 n = 1000
 z = npy.zeros((n,n))
 for i in range(2000):
 cs = ax.contourf(z)
 fig.savefig('test.png')
 ax.cla()
 print report_memory(), i

 I have not pasted in all of the output but just the first and last 25 
 lines:
 53356 0
 53360 1
 53360 2
 53360 3
 53360 4
 53360 5
 53360 6
 53360 7
 53360 8
 53360 9
 53360 10
 53360 11
 53360 12
 53360 13
 53360 14
 53360 15
 53360 16
 53360 17
 53356 18
 53360 19
 53360 20
 53360 21
 53360 22
 53360 23
 53356 24
 ...
 57552 1975
 57552 1976
 57552 1977
 57552 1978
 57552 1979
 57552 1980
 57552 1981
 57552 1982
 57552 1983
 57552 1984
 57552 1985
 57552 1986
 57552 1987
 57552 1988
 57552 1989
 57552 1990
 57552 1991
 57552 1992
 57552 1993
 57552 1994
 57552 1995
 57552 1996
 57552 1997
 57552 1998
 57552 1999

 --
  

 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   

 

 --
 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 

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


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in Agg backend?

2009-04-17 Thread Michael Droettboom
Are you able to run it inside of valgrind's massif tool?  Calling out to 
ps can be a bit spurious (particularly with a memory-pooling Python 
build) especially for a leak this small.

Mike

Andres Luhamaa wrote:
 Michael Droettboom wrote:
   
 I am not able to reproduce this leak here with 0.98.6svn from today on 
 RHEL4.  What platform are you on?

 (See attached massif profile -- the memory usage is flat...)

 Mike
 
 Well, in my setup I see similar behaviour as in the initial question. 
 Ubuntu 8.10 32bit, 2-days old svn verion of matplotlib.

 Andres
   
 Jesper Larsen wrote:
 
 Hi matplotlib developers and users,

 I have had some problems with a memory leak in a long running
 matplotlib based web application that I have developed
 (www.worldwildweather.com). I believe the problem is due to a memory
 leak in the Agg backend but I am not sure. Below is a script which for
 me results in a consistently increasing amount of  memory usage. I am
 using mpl version 0.98.6svn. The problem does not occur when the
 savefig command is commented out. And it does not occur when cs =
 ax.contourf(z) and ax.cla() are moved outside the loop (before and
 after respectively).

 Best regards,
 Jesper

 import os, gc
 import numpy as npy
 import matplotlib as mpl
 from matplotlib.figure import Figure
 from matplotlib.backends.backend_agg import FigureCanvasAgg as 
 FigureCanvas

 def report_memory():
 Report memory.
 gc.collect()
 pid = os.getpid()
 a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
 return int(a2[1].split()[1])

 fig = Figure(dpi=100)
 ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
 FigureCanvas(fig)

 n = 1000
 z = npy.zeros((n,n))
 for i in range(2000):
 cs = ax.contourf(z)
 fig.savefig('test.png')
 ax.cla()
 print report_memory(), i

 I have not pasted in all of the output but just the first and last 25 
 lines:
 53356 0
 53360 1
 53360 2
 53360 3
 53360 4
 53360 5
 53360 6
 53360 7
 53360 8
 53360 9
 53360 10
 53360 11
 53360 12
 53360 13
 53360 14
 53360 15
 53360 16
 53360 17
 53356 18
 53360 19
 53360 20
 53360 21
 53360 22
 53360 23
 53356 24
 ...
 57552 1975
 57552 1976
 57552 1977
 57552 1978
 57552 1979
 57552 1980
 57552 1981
 57552 1982
 57552 1983
 57552 1984
 57552 1985
 57552 1986
 57552 1987
 57552 1988
 57552 1989
 57552 1990
 57552 1991
 57552 1992
 57552 1993
 57552 1994
 57552 1995
 57552 1996
 57552 1997
 57552 1998
 57552 1999

 --
  

 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   
   
 

 --
 This SF.net email is sponsored by:
 High Quality Requirements in a Collaborative Environment.
 Download a free trial of Rational Requirements Composer Now!
 http://p.sf.net/sfu/www-ibm-com
 

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


 --
 Stay on top of everything new and different, both inside and 
 around Java (TM) technology - register by April 22, and save
 $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
 300 plus technical and hands-on sessions. Register today. 
 Use priority code J9JMT32. http://p.sf.net/sfu/p
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in Agg backend?

2009-04-17 Thread Andres Luhamaa
Well, I have never used it before but here is the output from valgrind 
masstif, can you figure out something from this? The mem usage from 
python was still increasing.


Andres

Michael Droettboom wrote:
Are you able to run it inside of valgrind's massif tool?  Calling out 
to ps can be a bit spurious (particularly with a memory-pooling Python 
build) especially for a leak this small.


Mike

Andres Luhamaa wrote:

Michael Droettboom wrote:
 
I am not able to reproduce this leak here with 0.98.6svn from today 
on RHEL4.  What platform are you on?


(See attached massif profile -- the memory usage is flat...)

Mike

Well, in my setup I see similar behaviour as in the initial question. 
Ubuntu 8.10 32bit, 2-days old svn verion of matplotlib.


Andres
 

Jesper Larsen wrote:
   

Hi matplotlib developers and users,

I have had some problems with a memory leak in a long running
matplotlib based web application that I have developed
(www.worldwildweather.com). I believe the problem is due to a memory
leak in the Agg backend but I am not sure. Below is a script which for
me results in a consistently increasing amount of  memory usage. I am
using mpl version 0.98.6svn. The problem does not occur when the
savefig command is commented out. And it does not occur when cs =
ax.contourf(z) and ax.cla() are moved outside the loop (before and
after respectively).

Best regards,
Jesper

import os, gc
import numpy as npy
import matplotlib as mpl
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as 
FigureCanvas


def report_memory():
Report memory.
gc.collect()
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
return int(a2[1].split()[1])

fig = Figure(dpi=100)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
FigureCanvas(fig)

n = 1000
z = npy.zeros((n,n))
for i in range(2000):
cs = ax.contourf(z)
fig.savefig('test.png')
ax.cla()
print report_memory(), i

I have not pasted in all of the output but just the first and last 
25 lines:

53356 0
53360 1
53360 2
53360 3
53360 4
53360 5
53360 6
53360 7
53360 8
53360 9
53360 10
53360 11
53360 12
53360 13
53360 14
53360 15
53360 16
53360 17
53356 18
53360 19
53360 20
53360 21
53360 22
53360 23
53356 24
...
57552 1975
57552 1976
57552 1977
57552 1978
57552 1979
57552 1980
57552 1981
57552 1982
57552 1983
57552 1984
57552 1985
57552 1986
57552 1987
57552 1988
57552 1989
57552 1990
57552 1991
57552 1992
57552 1993
57552 1994
57552 1995
57552 1996
57552 1997
57552 1998
57552 1999

-- 


This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

 



-- 


This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
 



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



-- 

Stay on top of everything new and different, both inside and around 
Java (TM) technology - register by April 22, and save

$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. Use 
priority code J9JMT32. http://p.sf.net/sfu/p

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






massif.out.25331.gz
Description: GNU Zip compressed data
--
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak in Agg backend?

2009-04-15 Thread Jesper Larsen
Hi matplotlib developers and users,

I have had some problems with a memory leak in a long running
matplotlib based web application that I have developed
(www.worldwildweather.com). I believe the problem is due to a memory
leak in the Agg backend but I am not sure. Below is a script which for
me results in a consistently increasing amount of  memory usage. I am
using mpl version 0.98.6svn. The problem does not occur when the
savefig command is commented out. And it does not occur when cs =
ax.contourf(z) and ax.cla() are moved outside the loop (before and
after respectively).

Best regards,
Jesper

import os, gc
import numpy as npy
import matplotlib as mpl
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas

def report_memory():
Report memory.
gc.collect()
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
return int(a2[1].split()[1])

fig = Figure(dpi=100)
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8])
FigureCanvas(fig)

n = 1000
z = npy.zeros((n,n))
for i in range(2000):
cs = ax.contourf(z)
fig.savefig('test.png')
ax.cla()
print report_memory(), i

I have not pasted in all of the output but just the first and last 25 lines:
53356 0
53360 1
53360 2
53360 3
53360 4
53360 5
53360 6
53360 7
53360 8
53360 9
53360 10
53360 11
53360 12
53360 13
53360 14
53360 15
53360 16
53360 17
53356 18
53360 19
53360 20
53360 21
53360 22
53360 23
53356 24
...
57552 1975
57552 1976
57552 1977
57552 1978
57552 1979
57552 1980
57552 1981
57552 1982
57552 1983
57552 1984
57552 1985
57552 1986
57552 1987
57552 1988
57552 1989
57552 1990
57552 1991
57552 1992
57552 1993
57552 1994
57552 1995
57552 1996
57552 1997
57552 1998
57552 1999

--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] memory leak

2008-11-20 Thread Benoît Zuber
Hi,
I have noticed a memory leak when using pylab.pcolor. Here is the code,
fa() and fb() do the same thing. The difference is the size of the array
which is passed to pcolor. With a large array pcolor leaks but not with a
small one.
Cheers,
Ben


import numpy as np
import matplotlib
matplotlib.use('Agg')
from matplotlib import pylab
def fa():
 This function leaks.

a = np.arange(1024**2)
a = a.reshape(1024,1024)
for i in range(1):
pylab.pcolor(a)
pylab.close()
def fb():
This function does not leak.

b = np.arange(1024)
b = b.reshape(32,32)
for i in range(1024):
pylab.pcolor(b)
pylab.close()


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory leak in basemap 0.98?

2008-10-22 Thread Jeff Whitaker
Mike Bauer wrote:
 Jeff,

 Using Python 2.6 results in the following Deprecation Warnings:

 /usr/local/lib/python2.6/site-packages/pytz/tzinfo.py:5: 
 DeprecationWarning: the sets module is deprecated
   from sets import Set
 /usr/local/lib/python2.6/site-packages/httplib2/__init__.py:29: 
 DeprecationWarning: the md5 module is deprecated; use hashlib instead
   import md5
 /usr/local/lib/python2.6/site-packages/httplib2/__init__.py:44: 
 DeprecationWarning: the sha module is deprecated; use the hashlib 
 module instead
   import sha

 Don't know if this is a problem.

Mike:  No, that's not a problem.  I've fixed the httplib2 warnings in SVN.

 I moved the basemap instance call outside the loop and the problem is 
 greatly reduced; although my memory usage still linearly increases but 
 by say 0.5 Gb instead of 6 Gb.
 I can live with that. Python2.5 lacks this increase as you expected.

 I ran trunk/matplotlib/unit//memleak_hawaii.py with python2.6:
   Average memory consumed per loop: 0.4428k bytes

 /Same call from python2.5:
 Average memory consumed per loop: 0.5672k bytes

 Seems basemap is needed to the memory leak.

 Mike

Can you send me the script you used to detect the leak?

-Jeff

 On Tue, Oct 21, 2008 at 5:36 PM, Jeff Whitaker [EMAIL PROTECTED] 
 mailto:[EMAIL PROTECTED] wrote:

 Mike Bauer wrote:

 I've been testing matplotlib and basemap (0.98.x and 0.99.x
 via svn source) and python 2.6 (via svn) on ubuntu 8.04 (AMD-64).

 I noticed that calling basemap in a loop results in a fairly
 steep linear increase in memory use; I burn though 6 Gb in a
 minute.

 Putting a loop in plotmap.py from the provided examples does
 this as well, so I don't think it's something I'm doing.

 Any ideas?

 Thanks.

 Mike

 P.S. Note that I'd like to use python 2.6 for the
 multiprocessing module (not in use in this script as of yet).
 My base install of python 2.5 with matplotlib and basemap
 (0.98.3 and 0.99.1 via sourceforge sourse) works fine.


 Mike:  Note that you don't actually need to recreate the basemap
 instance each time through the loop (since the map projection
 region is not changing).
 AFAIK there are no serious memory leaks in basemap with python 2.5
 - so if you can provide an example that triggers one I'd like to
 see it.
 Sounds like it might only be occurring with python 2.6?

 -Jeff

 -- 
 Jeffrey S. Whitaker Phone  : (303)497-6313
 Meteorologist   FAX: (303)497-6449
 NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED]
 325 BroadwayOffice : Skaggs Research Cntr 1D-113
 Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg




-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
325 BroadwayOffice : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory leak in basemap 0.98?

2008-10-21 Thread Jeff Whitaker
Mike Bauer wrote:
 I've been testing matplotlib and basemap (0.98.x and 0.99.x via svn 
 source) and python 2.6 (via svn) on ubuntu 8.04 (AMD-64).

 I noticed that calling basemap in a loop results in a fairly steep 
 linear increase in memory use; I burn though 6 Gb in a minute.

 Putting a loop in plotmap.py from the provided examples does this as 
 well, so I don't think it's something I'm doing.

 Any ideas?

 Thanks.

 Mike

 P.S. Note that I'd like to use python 2.6 for the multiprocessing 
 module (not in use in this script as of yet). My base install of 
 python 2.5 with matplotlib and basemap (0.98.3 and 0.99.1 via 
 sourceforge sourse) works fine.

Mike:  Note that you don't actually need to recreate the basemap 
instance each time through the loop (since the map projection region is 
not changing). 

AFAIK there are no serious memory leaks in basemap with python 2.5 - so 
if you can provide an example that triggers one I'd like to see it. 

Sounds like it might only be occurring with python 2.6?

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
325 BroadwayOffice : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] memory leak in Agg backend

2007-07-13 Thread Emanuele Passera
Hi all,
a few hours ago I have wtitten for a possible memory leak in Agg backend.
It was my fault. It was a bad placement of matplotlibrc file.
Sorry for the raised alarm.
Instead i am glad to say that I have checked for the Agg backend with a for 
statement of opening a figure, drawing, saving and closing and a real time 
monitoring of machine memory used and I can say that has not a memory leak.


-- 
--
Emanuele Passera

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak using matplotlib

2007-04-03 Thread Pellegrini Eric
Hi evebrybody,
   
  I started a discussion one week ago about a problem of memory leak using the 
following code:
   
  

  from Tkinter import *
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  import pylab
   
  def display():
  mat = pylab.zeros((100,100))
  pylab.ioff()
  image = pylab.matshow(mat)
  pylab.ion()
  pylab.close()
  can = FigureCanvasTkAgg(image, master=frame)
  can.show()
  can.get_tk_widget().grid(row = 0,column = 0)
   
  root = Tk()
  frame = Frame(root)
  frame.grid(row = 0,column = 0)
  canvas = Canvas(frame, width = 240, height = 240, relief = sunken, bg = 
white) 
  canvas.grid()
  button = Button(root,text=DisplayMatrix,command = display)
  button.grid(row = 1,column = 0)
  
***
   
  up to now, I have not found any way to solve it and unfortunately the 
proposed hints did not solve the problem (gc_collect(), clf(), cla()). Is there 
something new about this ?
   
  thanks
   
  Eric


-
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses.-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak using matplotlib

2007-04-03 Thread Eric Firing
Eric,

Not much progress, I think.  Memory leaks seem endemic to the gui 
backends, although Tk is by far the worst.  I have been trying to 
understand the gtk case in the hope of discovering some simple change in 
mpl code that might eliminate the problem there and turn out to be 
applicable to the other backends as well.  But I have not found the 
source of the problem, and it seems to occur even in a very simple test 
gui script using pure pygtk, with no mpl.  I need to do more testing to 
find out whether the gtk problem is specific to use of gtk.Toolbar, or 
whether it will occur with any nested widgets.  It seems that widgets 
are not getting destroyed completely; maybe there are some references 
lurking somewhere in the dark.  With gtk, the garbage collector does not 
find any cycles that it can't deal with, but if I remember correctly 
from earlier testing, this is not the case with Tk.

As a partial workaround, if you don't need the toolbar, try setting
rcParams['toolbar'] = None

This may make the leak much smaller.  I think the toolbar causes 
problems in all guis simply because it increases the complexity and 
number of widgets being tracked, if for no other reason.

I would be delighted if a gui guru would emerge with a thorough 
explanation and solution for the memory leaks occurring with repeated 
opening and closing of windows.

Eric



Pellegrini Eric wrote:
 Hi evebrybody,
  
 I started a discussion one week ago about a problem of memory leak using 
 the following code:
  
 
 from Tkinter import *
 from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
 import pylab
  
 def display():
 mat = pylab.zeros((100,100))
 pylab.ioff()
 image = pylab.matshow(mat)
 pylab.ion()
 pylab.close()
 can = FigureCanvasTkAgg(image, master=frame)
 can.show()
 can.get_tk_widget().grid(row = 0,column = 0)
  
 root = Tk()
 frame = Frame(root)
 frame.grid(row = 0,column = 0)
 canvas = Canvas(frame, width = 240, height = 240, relief = sunken, bg 
 = white)
 canvas.grid()
 button = Button(root,text=DisplayMatrix,command = display)
 button.grid(row = 1,column = 0)
 ***
  
 up to now, I have not found any way to solve it and unfortunately the 
 proposed hints did not solve the problem (gc_collect(), clf(), cla()). 
 Is there something new about this ?
  
 thanks
  
 Eric
 
 
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos 
 questions ! Profitez des connaissances, des opinions et des expériences 
 des internautes sur Yahoo! Questions/Réponses 
 http://fr.rd.yahoo.com/evt=42054/*http://fr.answers.yahoo.com.
 
 
 
 
 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys-and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 
 
 
 
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread Jesper Larsen
Hi matplotlib users,

I'm using matplotlib for a long running process. Unfortunately the memory 
usage continue to grow as the process runs. I have appended a simple example 
which illustrates this at the end of this mail. Unfortunately I haven't 
figured out how to use the information obtainable from gc for anything useful 
in this regards.

Kind regards,
Jesper


My system is:

 uname -a
Linux sea 2.6.15-28-686 #1 SMP PREEMPT Thu Feb 1 16:14:07 UTC 2007 i686 
GNU/Linux

 python
Python 2.4.4 (#1, Nov 16 2006, 13:39:46)
[GCC 3.3.3 (Debian)] on linux2
Type help, copyright, credits or license for more information.
 import matplotlib
 print matplotlib.__version__
0.87.6
 from matplotlib.toolkits import basemap
 print basemap.__version__
0.9.4

Test code:

import os, gc
import PyNGL.Nio as Nio
from matplotlib.toolkits import basemap
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
import pylab

def report_memory(i):
  pid = os.getpid()
  a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
  print i, ' ', a2[1],
  return int(a2[1].split()[1])

def plot():
  #gc.set_debug(gc.DEBUG_LEAK)
  lon = pylab.linspace(-4.08300018311, 30.25, 207)
  lat = pylab.linspace(48.542371, 65.8499984741, 174)
  xo, yo = pylab.meshgrid(lon, lat)
  bmap = basemap.Basemap(-4, 48, 30, 66)
  xlon, ylat = bmap(xo,yo)

  fig = pylab.Figure()
  canvas = FigureCanvas(fig)

  i = 0
  while True:
report_memory(i)

fig.clear()
cs = bmap.contourf(xlon, ylat, xo)
del cs

i += 1

if __name__ == '__main__': plot()

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread Jeff Whitaker
Jesper Larsen wrote:
 Hi matplotlib users,

 I'm using matplotlib for a long running process. Unfortunately the memory 
 usage continue to grow as the process runs. I have appended a simple example 
 which illustrates this at the end of this mail. Unfortunately I haven't 
 figured out how to use the information obtainable from gc for anything useful 
 in this regards.

 Kind regards,
 Jesper


 My system is:

   
 uname -a
 
 Linux sea 2.6.15-28-686 #1 SMP PREEMPT Thu Feb 1 16:14:07 UTC 2007 i686 
 GNU/Linux

   
 python
 
 Python 2.4.4 (#1, Nov 16 2006, 13:39:46)
 [GCC 3.3.3 (Debian)] on linux2
 Type help, copyright, credits or license for more information.
   
 import matplotlib
 print matplotlib.__version__
 
 0.87.6
   
 from matplotlib.toolkits import basemap
 print basemap.__version__
 
 0.9.4

 Test code:

 import os, gc
 import PyNGL.Nio as Nio
 from matplotlib.toolkits import basemap
 from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
 import pylab

 def report_memory(i):
   pid = os.getpid()
   a2 = os.popen('ps -p %d -o rss,vsz,%%mem' % pid).readlines()
   print i, ' ', a2[1],
   return int(a2[1].split()[1])

 def plot():
   #gc.set_debug(gc.DEBUG_LEAK)
   lon = pylab.linspace(-4.08300018311, 30.25, 207)
   lat = pylab.linspace(48.542371, 65.8499984741, 174)
   xo, yo = pylab.meshgrid(lon, lat)
   bmap = basemap.Basemap(-4, 48, 30, 66)
   xlon, ylat = bmap(xo,yo)

   fig = pylab.Figure()
   canvas = FigureCanvas(fig)

   i = 0
   while True:
 report_memory(i)

 fig.clear()
 cs = bmap.contourf(xlon, ylat, xo)
 del cs

 i += 1

 if __name__ == '__main__': plot()

   


Jesper:  For now I recommend adding 'pylab.cla()' after the fig.clear() 
as a workaround.  I don't really understand why that is necessary - 
perhaps John or Eric can clarify whether this is indeed a bug.

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
325 BroadwayOffice : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread Eric Firing

Jeff Whitaker wrote:

Jesper Larsen wrote:

Hi matplotlib users,

I'm using matplotlib for a long running process. Unfortunately the memory 
usage continue to grow as the process runs. I have appended a simple example 
which illustrates this at the end of this mail. Unfortunately I haven't 
figured out how to use the information obtainable from gc for anything useful 
in this regards.

[...]
  
Jesper:  Looks to me like the memory leak is not in Basemap, but somehow 
the fig.clear() is not working properly.  Replacing the fig.clear() with 
pylab.gca() gets rid of the memory leak.  I will investigate further ...



-Jeff



Jeff, this might be related to the leak illustrated in the attached 
script, based on an earlier report.  (I don't recall who reported it.)


Eric

#!/usr/bin/env python
'''
This illustrates a leak that occurs with any interactive backend.
'''
import os, sys, time
import matplotlib
matplotlib.use('GtkAgg') # or TkAgg or WxAgg
import pylab

def report_memory(i):
pid = os.getpid()
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
print i, '  ', a2[1],
return int(a2[1].split()[1])



# take a memory snapshot on indStart and compare it with indEnd

indStart, indEnd = 30, 201
for i in range(indEnd):

pylab.figure(1)
pylab.close(1)
val = report_memory(i)
if i==indStart: start = val # wait a few cycles for memory usage to stabilize

end = val
print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread Jeff Whitaker
Eric Firing wrote:
 Jeff Whitaker wrote:
 Jesper Larsen wrote:
 Hi matplotlib users,

 I'm using matplotlib for a long running process. Unfortunately the 
 memory usage continue to grow as the process runs. I have appended a 
 simple example which illustrates this at the end of this mail. 
 Unfortunately I haven't figured out how to use the information 
 obtainable from gc for anything useful in this regards.
 [...]
   
 Jesper:  Looks to me like the memory leak is not in Basemap, but 
 somehow the fig.clear() is not working properly.  Replacing the 
 fig.clear() with pylab.gca() gets rid of the memory leak.  I will 
 investigate further ...


 -Jeff


 Jeff, this might be related to the leak illustrated in the attached 
 script, based on an earlier report.  (I don't recall who reported it.)

 Eric


Eric:  Don't think so, since Jesper's script leaks even when the backend 
is set to 'Agg' (while the one you sent doesn't).

-Jeff

-- 
Jeffrey S. Whitaker Phone  : (303)497-6313
Meteorologist   FAX: (303)497-6449
NOAA/OAR/PSD  R/PSD1Email  : [EMAIL PROTECTED]
325 BroadwayOffice : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web: http://tinyurl.com/5telg


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread John Hunter
On 3/26/07, Jeff Whitaker [EMAIL PROTECTED] wrote:

 Jesper:  For now I recommend adding 'pylab.cla()' after the fig.clear()
 as a workaround.  I don't really understand why that is necessary -
 perhaps John or Eric can clarify whether this is indeed a bug.

 I suggest adding a gc.collect after the figure.clear() and see if
this fixes things.

JDH

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Memory leak in basemap or matplotlib

2007-03-26 Thread John Hunter
On 3/26/07, Jeff Whitaker [EMAIL PROTECTED] wrote:
 John Hunter wrote:

 John:  Nope, that has no effect.  What does cla clean up that clf doesn't?

Well, it flushes all the lines, removes the ticks, that kind of thing.
 But fig.clear sets

self.axes = []

so if there are no references to the axes anywhere, gc.collect()
should force a clean up and a purging of all the axes artists.  Ie, it
should matter if Axes.cla does self.lines=[] if the figure clear
removes all references to the axes.  I'm wondering if someone
somewhere in mpl is keeping a reference to the axes

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Memory leak with FigureCanvasTk

2007-03-20 Thread Pellegrini Eric
Hi,
   
  I have a problem of memory leak using the following code:
   
  

  from Tkinter import *
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  import pylab
   
  def display():
  mat = pylab.zeros((100,100))
  pylab.ioff()
  image = pylab.matshow(mat)
  pylab.ion()
  pylab.close()
  can = FigureCanvasTkAgg(image, master=frame)
  can.show()
  can.get_tk_widget().grid(row = 0,column = 0)
   
  root = Tk()
  frame = Frame(root)
  frame.grid(row = 0,column = 0)
  canvas = Canvas(frame, width = 240, height = 240, relief = sunken, bg = 
white) 
  canvas.grid()
  button = Button(root,text=DisplayMatrix,command = display)
  button.grid(row = 1,column = 0)
  
***
   
  would you have any idea of what is going wrong ?
   
  Thank you very much
   
  Eric
   
   
   
   
   
   
   
   
   
   


-
 Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! 
Profitez des connaissances, des opinions et des expériences des internautes sur 
Yahoo! Questions/Réponses.-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] memory leak in matplotlib wxApp?

2006-12-19 Thread John Hunter
 Olivier == Olivier ATTEIA [EMAIL PROTECTED] writes:

Olivier Hello, sorry to bother you but I did not find a reply
Olivier elsewhere, I am using matplotlib with python 2.4 and
Olivier windows XP and it is a really nice tool. It is inside a
Olivier wxapplication.  I have a problem because the user can
Olivier change the graph settings as he wants and draws several
Olivier times contours from 50 by 200 matrices.  After some time
Olivier the program slows down and the memory is increasing
Olivier regularly. I don't understand because I use a command
Olivier similar as in matplotlib clear command : collections=[]
Olivier between each drawing.  I tried in a simpler way : just
Olivier start matplotlib(even in tk mode), make a plot(x,y) with
Olivier x=randn(100,100). First it takes a lot of memory (more
Olivier than 50 Mb). And when you clear hte figure the meory
Olivier remains high, or when you set holds(False) and make a
Olivier simple plot the first plot disappears but the memory is
Olivier still high.  Do you have any idea Thanks a lot Sincerely
Olivier O. Atteia

Hey Olivier,  questions should go to the matplotlib-users mailing
list.  I'm forwarding this on.  You can subscribe at 

http://sourceforge.net/mailarchive/forum.php?forum_id=33405

JDH




-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users