8000 patched some mem leaks in new agg backend methods · matplotlib/matplotlib@fec122a · GitHub
[go: up one dir, main page]

Skip to content

Commit fec122a

Browse files
committed
patched some mem leaks in new agg backend methods
svn path=/trunk/matplotlib/; revision=968
1 parent 28a43e3 commit fec122a

File tree

8 files changed

+51
-43
lines changed

8 files changed

+51
-43
lines changed

CHANGELOG

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

3-
43
2005-02-14 fix bug in cbook alltrue() and onetrue() - SC
54

65
2005-02-11 updated qtagg backend from Ted - JDH
@@ -9,8 +8,6 @@ New entries should be added at the top
98

109
2005-02-09 new zorder example for fine control in zorder_demo.py - FP
1110

12-
2005-02-09 backend renderer draw_lines now has transform in backend,
13-
1411
2005-02-09 backend renderer draw_lines now has transform in backend,
1512
as in draw_markers; use numerix in _backend_agg, aded small
1613
line optimization to agg

lib/matplotlib/artist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ class Artist:
2828
aname = 'Artist'
2929
zorder = 0
3030
def __init__(self):
31-
3231
self.figure = None
32+
3333
self._transform = identity_transform()
34+
self._transform = None
3435
self._transformSet = False
3536
self._visible = True
3637
self._alpha = 1.0

lib/matplotlib/axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ def add_line(self, l):
706706
l.get_transform(), zip(xdata, ydata))
707707
xdata, ydata = zip(*xys)
708708
self.update_datalim_numerix( xdata, ydata )
709-
709+
#self.update_datalim(zip(xdata, ydata))
710710
self.lines.append(l)
711711

712712
def _get_verts_in_data_coords(self, trans, xys):

lib/matplotlib/axis.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def __init__(self, axes, loc, label,
7373
self._loc = loc
7474
self._size = size
7575
self._pad = Value(pad)
76-
self._padPixels = self.figure.dpi*self._pad*Value(1/72.0)
76+
77+
self._padPixels = self.figure.dpi*self._pad*Value(1/72.0)
7778

7879

7980
self.tick1line = self._get_tick1line(loc)
@@ -233,18 +234,19 @@ def _get_text2(self, loc):
233234
self._set_artist_props(t)
234235
return t
235236

236-
def _get_tick1line(self, loc):
237+
def _get_tick1line(self, loc):
237238
'Get the default line2D instance'
238239
# x in data coords, y in axes coords
239240
l = Line2D( xdata=(loc, loc), ydata=(0, 0),
240241
color='k',
242+
linestyle = 'None',
241243
antialiased=False,
242244
marker = TICKUP,
243245
markersize=self._size,
244246
)
245247

246248
l.set_transform( blend_xy_sep_transform( self.axes.transData,
247-
self.axes.transAxes) )
249+
self.axes.transAxes) )
2 B41A 48250
self._set_artist_props(l)
249251
return l
250252

@@ -253,6 +255,7 @@ def _get_tick2line(self, loc):
253255
# x in data coords, y in axes coords
254256
l = Line2D( xdata=(loc, loc), ydata=(1,1),
255257
color='k',
258+
linestyle = 'None',
256259
antialiased=False,
257260
marker = TICKDOWN,
258261
markersize=self._size,
@@ -350,17 +353,18 @@ def _get_text2(self, loc):
350353
self._set_artist_props(t)
351354
return t
352355

353-
def _get_tick1line(self, loc):
356+
def _get_tick1line(self, loc):
354357
'Get the default line2D instance'
355358
# x in axes coords, y in data coords
356359

357360
l = Line2D( (0, 0), (loc, loc), color='k',
358361
antialiased=False,
359362
marker = TICKRIGHT,
363+
linestyle = 'None',
360364
markersize=self._size,
361365
)
362366
l.set_transform( blend_xy_sep_transform( self.axes.transAxes,
363-
self.axes.transData) )
367+
self.axes.transData) )
364368
self._set_artist_props(l)
365369
return l
366370

@@ -370,6 +374,7 @@ def _get_tick2line(self, loc):
370374
l = Line2D( (1, 1), (0, 0), color='k',
371375
antialiased=False,
372376
marker = TICKLEFT,
377+
linestyle = 'None',
373378
markersize=self._size,
374379
)
375380

@@ -378,7 +383,7 @@ def _get_tick2line(self, loc):
378383
self._set_artist_props(l)
379384
return l
380385

381-
def _get_gridline(self, loc):
386+
def _get_gridline(self, loc):
382387
'Get the default line2D instance'
383388
# x in axes coords, y in data coords
384389
l = Line2D( xdata=(0,1), ydata=(loc,loc),
@@ -439,10 +444,16 @@ def __init__(self, axes):
439444
"""
440445
Artist.__init__(self)
441446
self.set_figure(axes.figure)
442-
447+
443448
self.axes = axes
444449
self.major = Ticker()
445450
self.minor = Ticker()
451+
#class dummy:
452+
# locator = None
453+
# formatter = None
454+
#self.major = dummy()
455+
#self.minor = dummy()
456+
446457
self.label = self._get_label()
447458
self.majorTicks = []
448459
self.minorTicks = []
@@ -470,6 +481,7 @@ def cla(self):
470481

471482
popall(self.majorTicks)
472483
popall(self.minorTicks)
484+
473485
self.majorTicks.extend([self._get_tick(major=True) for i in range(1)])
474486
self.minorTicks.extend([self._get_tick(major=False) for i in range(1)])
475487

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def __init__(self, xdata, ydata,
9595
9696
"""
9797
Artist.__init__(self)
98+
9899
#convert sequences to numeric arrays
99100
if not iterable(xdata):
100101
raise RuntimeError('xdata must be a sequence')
@@ -260,7 +261,6 @@ def draw(self, renderer):
260261
#renderer.open_group('line2d')
261262

262263
self._newstyle = hasattr(renderer, 'draw_markers')
263-
264264
gc = renderer.new_gc()
265265
gc.set_foreground(self._color)
266266
gc.set_antialiased(self._antialiased)

src/_backend_agg.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,6 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
893893

894894
_VERBOSE("RendererAgg::draw_lines");
895895
args.verify_length(4);
896-
897896
GCAgg gc = GCAgg(args[0], dpi);
898897
set_clipbox_rasterizer(gc.cliprect);
899898

@@ -963,13 +962,8 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
963962

964963
//don't render line segments less that on pixel long!
965964
if (!moveto && (i>0) && fabs(thisx-lastx)<1.0 && fabs(thisy-lasty)<1.0) {
966-
//std::cout << "skipping " << thisx << " " << thisy << " " << lastx << " " << lasty << " " << fabs(thisx-lastx) << " " << fabs(thisy-lasty) << std::endl;
967965
continue;
968966
}
969-
else {
970-
//std::cout << "drawing " << thisx << " " << thisy << " " << lastx << " " << lasty << std::endl;
971-
972-
}
973967

974968
lastx = thisx;
975969
lasty = thisy;
@@ -980,18 +974,13 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
980974

981975
moveto = false;
982976

983-
/*
984-
if ((i>0) && (i%100000==0)) {
985-
//render the sucker
986-
_render_lines_path(path, gc);
987-
path.remove_all();
988-
path.move_to(thisx, thisy);
989-
}
990-
*/
991977
}
992978

979+
Py_XDECREF(xa);
980+
Py_XDECREF(ya);
993981

994982
_render_lines_path(path, gc);
983+
995984
_VERBOSE("RendererAgg::draw_lines DONE");
996985
return Py::Object();
997986

@@ -1046,6 +1035,7 @@ Py::Object
10461035
RendererAgg::draw_markers(const Py::Tuple& args) {
10471036
//draw_markers(gc, path, xo, yo, transform)
10481037
theRasterizer->reset_clipping();
1038+
10491039
_VERBOSE("RendererAgg::draw_markers");
10501040
args.verify_length(5);
10511041

@@ -1195,7 +1185,10 @@ RendererAgg::draw_markers(const Py::Tuple& args) {
11951185
agg::render_scanlines(sa, sl, *rendererAA);
11961186

11971187
} //for each marker
1198-
1188+
1189+
Py_XDECREF(xa);
1190+
Py_XDECREF(ya);
1191+
11991192
delete [] strokeCache;
12001193
delete [] fillCache;
12011194
return Py::Object();

src/_transforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ Bbox::update_numerix(const Py::Tuple &args) {
460460

461461
Py_XDECREF(x);
462462
Py_XDECREF(y);
463-
463+
464464

465465
_ll->x_api()->set_api(minx);
466466
_ll->y_api()->set_api(miny);

unit/memleak_hawaii3.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import os, sys, time
44
import matplotlib
5-
matplotlib.interactive(True)
5+
#matplotlib.interactive(True)
66
#matplotlib.use('Cairo')
7-
matplotlib.use('TkAgg')
7+
matplotlib.use('Agg')
88
from pylab import *
99

1010

@@ -17,33 +17,38 @@ def report_memory(i):
1717

1818

1919
# take a memory snapshot on indStart and compare it with indEnd
20-
indStart, indEnd = 30, 150
20+
21+
indStart, indEnd = 30, 201
2122
for i in range(indEnd):
22-
ind = arange(100)
23-
xx = rand(len(ind))
23+
2424
figure(1); clf()
25-
ioff()
25+
2626
subplot(221)
27-
plot(ind, xx)
27+
t1 = arange(0.0, 2.0, 0.01)
28+
y = sin(2*pi*t1)
29+
plot(t1,y,'-')
30+
plot(t1, rand(len(t1)), 's', hold=True)
31+
2832

2933
subplot(222)
3034
X = rand(50,50)
31-
35+
3236
imshow(X)
3337
subplot(223)
34-
scatter(rand(50), rand(50))
38+
scatter(rand(50), rand(50), s=100*rand(50), c=rand(50))
3539
subplot(224)
3640
pcolor(10*rand(50,50))
37-
ion()
38-
draw()
41+
#ion()
42+
#draw()
3943

4044
#ioff()
41-
#savefig('tmp%d' % i, dpi = 75)
45+
4246
#fd = file('tmp%d' % i, 'wb')
4347
#savefig(fd, dpi = 75)
4448
#fd.close()
45-
#close(1)
46-
49+
savefig('tmp%d' % i, dpi = 75)
50+
close(1)
51+
#break
4752

4853
val = report_memory(i)
4954
if i==indStart: start = val # wait a few cycles for memory usage to stabilize

0 commit comments

Comments
 (0)
0