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

Skip to content

Commit 47a4923

Browse files
committed
fixed an agg to string mem leak
svn path=/trunk/matplotlib/; revision=376
1 parent 961a44c commit 47a4923

5 files changed

Lines changed: 56 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
New entries should be added at the top
22
=======
33

4+
2004-07-01 Fixed a memory leak in image and agg to string methods
5+
46
2004-06-25 Fixed fonts_demo spacing problems and added a kwargs
57
version of the fonts_demo fonts_demo_kw.py - JDH
68

TODO

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,5 @@
452452
-- DONE clear agg bg to 0 alpha
453453

454454
-- DONE reset build flags in setup.py
455+
456+
-- ad wxagg extension code to goals

examples/dynamic_image_gtk.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
"""
3+
An animated image - Thanks to Andrew Straw who originally provided
4+
this examples as dynamic_image_wx.py
5+
"""
6+
import sys, time, os, gc
7+
from matplotlib import rcParams
8+
# there is a bug in Numeric 23.1 that crashes with this examples
9+
rcParams['numerix'] = 'numarray'
10+
11+
from matplotlib.matlab import *
12+
import gtk
13+
14+
fig = figure(1)
15+
a = subplot(111)
16+
x = arange(120.0)*2*pi/120.0
17+
x.resize((100,120))
18+
y = arange(100.0)*2*pi/100.0
19+
y.resize((120,100))
20+
y = transpose(y)
21+
z = sin(x) + cos(y)
22+
im = a.imshow( z, cmap=cm.jet)#, interpolation='nearest')
23+
24+
25+
manager = get_current_fig_manager()
26+
cnt = 0
27+
tstart = time.time()
28+
def updatefig(*args):
29+
global x, y, cnt, start
30+
x += pi/15
31+
y += pi/20
32+
z = sin(x) + cos(y)
33+
im.set_array(z)
34+
manager.canvas.draw()
35+
cnt += 1
36+
if cnt==50:
37+
print 'FPS', cnt/(time.time() - tstart)
38+
return gtk.FALSE
39+
return True
40+
41+
42+
cnt = 0
43+
44+
gtk.idle_add(updatefig)
45+
show()

src/_backend_agg.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ RendererAgg::write_png(const Py::Tuple& args)
10051005
return Py::Object();
10061006
}
10071007

1008+
10081009
Py::Object
10091010
RendererAgg::tostring_rgb(const Py::Tuple& args) {
10101011
//"Return the rendered buffer as an RGB string";
@@ -1013,8 +1014,7 @@ RendererAgg::tostring_rgb(const Py::Tuple& args) {
10131014

10141015
args.verify_length(0);
10151016
int row_len = width*3;
1016-
unsigned char* buf_tmp =
1017-
new unsigned char[row_len * height];
1017+
unsigned char buf_tmp[row_len * height];
10181018
agg::rendering_buffer renderingBufferTmp;
10191019
renderingBufferTmp.attach(buf_tmp,
10201020
width,
@@ -1025,14 +1025,13 @@ RendererAgg::tostring_rgb(const Py::Tuple& args) {
10251025

10261026

10271027
//todo: how to do this with native CXX
1028-
return Py::Object(Py_BuildValue("s#",
1028+
return Py::asObject(Py_BuildValue("s#",
10291029
buf_tmp,
10301030
row_len * height));
10311031
//len = row_len * height
10321032
//std::string s(buf_tmp);
10331033
//return Py::String(buf_tmp, row_len * height);
10341034
}
1035-
10361035
agg::rgba
10371036
RendererAgg::get_color(const Py::Object& gc) {
10381037

src/_image.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ Image::as_str(const Py::Tuple& args) {
152152
args.verify_length(1);
153153
int flipud = Py::Int(args[0]);
154154
if (!flipud) {
155-
return Py::Object(Py_BuildValue("lls#", rowsOut, colsOut,
156-
bufferOut, colsOut*rowsOut*4));
155+
return Py::asObject(Py_BuildValue("lls#", rowsOut, colsOut,
156+
bufferOut, colsOut*rowsOut*4));
157157
}
158158

159159
const size_t NUMBYTES(rowsOut * colsOut * BPP);
@@ -167,8 +167,8 @@ Image::as_str(const Py::Tuple& args) {
167167
buffer[ind++] = *(bufferOut + start + j);
168168
}
169169
}
170-
return Py::Object(Py_BuildValue("lls#", rowsOut, colsOut,
171-
buffer, NUMBYTES));
170+
return Py::asObject(Py_BuildValue("lls#", rowsOut, colsOut,
171+
buffer, NUMBYTES));
172172

173173
}
174174

0 commit comments

Comments
 (0)