Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e59c8cd

Browse files
committed
patched leak in BufferRegion.to_string
svn path=/trunk/matplotlib/; revision=2582
1 parent 4226399 commit e59c8cd

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

examples/animation_blit_qt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
TRUE = 1
1414
FALSE = 0
15+
ITERS = 200
1516

1617
import pylab as p
1718
import matplotlib.numerix as nx
@@ -44,9 +45,9 @@ def timerEvent(self, evt):
4445
# just redraw the axes rectangle
4546
self.canvas.blit(self.ax.bbox)
4647

47-
if self.cnt==200:
48+
if self.cnt==ITERS:
4849
# print the timing info and quit
49-
print 'FPS:' , 200/(time.time()-self.tstart)
50+
print 'FPS:' , ITERS/(time.time()-self.tstart)
5051
sys.exit()
5152

5253
else:

lib/matplotlib/backends/backend_qtagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def paintEvent( self, e ):
103103
p.drawRect( self.rect[0], self.rect[1], self.rect[2], self.rect[3] )
104104

105105
# we are blitting here
106-
else: # TODO: Fix memory leak
106+
else:
107107
bbox = self.replot
108108
w, h = int(bbox.width()), int(bbox.height())
109109
l, t = bbox.ll().x().get(), bbox.ur().y().get()

src/_backend_agg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ GCAgg::_set_clip_rectangle( const Py::Object& gc) {
189189

190190
Py::Object BufferRegion::to_string(const Py::Tuple &args) {
191191

192-
return Py::String(PyString_FromStringAndSize((const char*)aggbuf.data,aggbuf.height*aggbuf.stride));
192+
// owned=true to prevent memory leak
193+
return Py::String(PyString_FromStringAndSize((const char*)aggbuf.data,aggbuf.height*aggbuf.stride), true);
193194
}
194195

195196

0 commit comments

Comments
 (0)