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

Skip to content

Commit 9f51a84

Browse files
committed
more mem leak fixes in transforms and ft2font
svn path=/trunk/matplotlib/; revision=340
1 parent 79a0e81 commit 9f51a84

8 files changed

Lines changed: 99 additions & 19 deletions

File tree

.matplotlibrc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,24 @@ interactive : False # see http://matplotlib.sourceforge.net/interactive.htm
3636
lines.linewidth : 0.5 # line width in points
3737
lines.linestyle : - # solid line
3838
lines.color : b # blue; color format or hex string
39-
lines.markersize : 6 # markersize, in points
40-
lines.antialiased : True # render lines in antialised (no jaggies)
39+
lines.markerfacecolor : b
40+
lines.markeredgecolor : k
41+
lines.markeredgewidth : 0.5
42+
lines.markersize : 6 # markersize, in points
43+
lines.antialiased : True # render lines in antialised (no jaggies)
4144
lines.data_clipping : False # Use data clipping in addition to viewport
42-
# clipping. Useful if you plot long data
43-
# sets with only a fraction in the viewport
45+
# clipping. Useful if you plot long data
46+
# sets with only a fraction in the viewport
47+
48+
### Patches
49+
# Patches are graphical objects that fill 2D space, like polygons or
50+
# circles. See
51+
# http://matplotlib.sourceforge.net/matplotlib.patches.html for more
52+
# information on patch properties
53+
patch.linewidth : 0.5 # edge width in points
54+
patch.facecolor : b
55+
patch.edgecolor : k
56+
patch.antialiased : True # render patches in antialised (no jaggies)
4457

4558
### FONT
4659
#

CHANGELOG

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
New entries should be added at the top
2+
=======
3+
4+
5+
2004-06-11 More memory leak fixes in transforms and ft2font - JDH
26

37
2004-06-11 Eliminated numerix .numerix file and environment variable
48
NUMERIX. Fixed bug which prevented command line overrides:
59
--numarray or --numeric. - JTM
610

11+
2004-06-10 Added rc configuration function rc; deferred all rc param
12+
setting until object creation time; added new rc attrs:
13+
lines.markerfacecolor, lines.markeredgecolor,
14+
lines.markeredgewidth, patch.linewidth, patch.facecolor,
15+
patch.edgecolor, patch.antialiased - JDH
16+
17+
18+
---------------------------------------------------------------
19+
2004-06-09 0.54.2 released
20+
721
2004-06-08 Rewrote ft2font using CXX as part of general memory leak
822
fixes; also fixed transform memory leaks - JDH
923

TODO

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,24 @@
410410

411411
-- use RGBA throughout lib
412412

413-
-- fix wrt log and recommit cvs
413+
-- DONE fix wrt log and recommit cvs
414414

415-
-- check Fernando's bounds problem with pcolor.
415+
-- check Fernando's bounds problem with pcolor.
416+
417+
-- Write John's Letter
418+
419+
-- add default args to imshow per Fernando's suggestion
420+
421+
-- DONE - check out Fernando's wx prob
422+
423+
-- add interp and aspect info to imshow doc
424+
425+
-- add write png method to image module
426+
427+
-- change the viewlim on call to log if min ax <=0
428+
429+
-- fix set_def font example and update API_CHANGES
430+
431+
-- upload 0.54.2 zip
432+
433+
-- need a new way to indicate linestyle=None!

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
respectively; set them to 0 if you do not want to build them
77
"""
88

9+
# The NUMERIX
910
NUMERIX = 'Numeric' # or numarray
1011
# build the freetype2 interface - this is required for mathtext
1112
# Requires freetype2, and libz

src/_backend_agg.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,23 +157,23 @@ RendererAgg::draw_polygon(const Py::Tuple& args) {
157157
std::cout << "RendererAgg::draw_polygon" << std::endl;
158158

159159
args.verify_length(3);
160-
160+
161161
Py::Object gcEdge( args[0] );
162162
Py::Object rgbFaceMaybeNone( args[1] );
163163
Py::SeqBase<Py::Object> points( args[2] );
164-
164+
165165

166166
set_clip_rectangle(gcEdge);
167167
agg::gen_stroke::line_cap_e cap = get_linecap(gcEdge);
168168
agg::gen_stroke::line_join_e join = get_joinstyle(gcEdge);
169169

170170
double lw = points_to_pixels ( gcEdge.getAttr("_linewidth") ) ;
171-
171+
172172
size_t Npoints = points.length();
173173
if (Npoints<=0)
174174
return Py::Object();
175-
176-
175+
176+
177177
// dump the x.y vertices into a double array for faster look ahread
178178
// and behind access
179179
double xs[Npoints];
@@ -187,6 +187,7 @@ RendererAgg::draw_polygon(const Py::Tuple& args) {
187187

188188
}
189189

190+
190191
agg::path_storage path;
191192
for (size_t j=0; j<Npoints; ++j) {
192193

@@ -197,7 +198,7 @@ RendererAgg::draw_polygon(const Py::Tuple& args) {
197198
else path.line_to(x,y);
198199
}
199200
path.close_polygon();
200-
201+
201202
agg::rgba edgecolor = get_color(gcEdge);
202203

203204

@@ -209,7 +210,7 @@ RendererAgg::draw_polygon(const Py::Tuple& args) {
209210
theRasterizer->add_path(path);
210211
theRasterizer->render(*slineP8, *theRenderer);
211212
}
212-
213+
213214
//now fill the edge
214215
agg::conv_stroke<agg::path_storage> stroke(path);
215216
stroke.width(lw);

src/_image.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,10 @@ _image_fromarray(PyObject *self, PyObject *args) {
569569
ImageObject *imo;
570570

571571
imo = newImageObject(args);
572-
if ( imo == NULL )
572+
if ( imo == NULL ) {
573+
Py_XDECREF(A);
573574
return NULL;
575+
}
574576

575577
imo->rowsIn = A->dimensions[0];
576578
imo->colsIn = A->dimensions[1];
@@ -604,6 +606,7 @@ _image_fromarray(PyObject *self, PyObject *args) {
604606
if (A->dimensions[2] != 3 && A->dimensions[2] != 4 ) {
605607
PyErr_SetString(PyExc_ValueError,
606608
"3rd dimension must be length 3 (RGB) or 4 (RGBA)");
609+
Py_XDECREF(A);
607610
return NULL;
608611

609612
}
@@ -635,9 +638,10 @@ _image_fromarray(PyObject *self, PyObject *args) {
635638
else { // error
636639
PyErr_SetString(PyExc_ValueError,
637640
"Illegal array rank; must be rank; must 2 or 3");
641+
Py_XDECREF(A);
638642
return NULL;
639643
}
640-
644+
Py_XDECREF(A);
641645
return (PyObject *)imo;
642646
}
643647

src/_transforms.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
#include <functional>
22
#include <numeric>
33
#include "_transforms.h"
4-
4+
5+
56
#ifdef NUMARRAY
67
#include "numarray/arrayobject.h"
78
#else
89
#include "Numeric/arrayobject.h"
910
#endif
1011

12+
13+
14+
1115
#define DEBUG_MEM 0
1216

1317

@@ -650,6 +654,7 @@ Transformation::numerix_x_y(const Py::Tuple & args) {
650654
if (x==NULL)
651655
throw Py::TypeError("Transformation::numerix_x_y expected numerix array");
652656

657+
653658
PyArrayObject *y = (PyArrayObject *) PyArray_ContiguousFromObject(yo.ptr(), PyArray_DOUBLE, 1, 1);
654659

655660
if (y==NULL)
@@ -667,13 +672,21 @@ Transformation::numerix_x_y(const Py::Tuple & args) {
667672

668673
int dimensions[1];
669674
dimensions[0] = Nx;
675+
676+
670677
PyArrayObject *retx = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE);
671-
if (retx==NULL)
678+
if (retx==NULL) {
679+
Py_XDECREF(x);
680+
Py_XDECREF(y);
672681
throw Py::RuntimeError("Could not create return x array");
682+
}
673683

674684
PyArrayObject *rety = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_DOUBLE);
675-
if (retx==NULL)
685+
if (rety==NULL) {
686+
Py_XDECREF(x);
687+
Py_XDECREF(y);
676688
throw Py::RuntimeError("Could not create return x array");
689+
}
677690

678691
for (size_t i=0; i< Nx; ++i) {
679692

@@ -684,10 +697,15 @@ Transformation::numerix_x_y(const Py::Tuple & args) {
684697
*(double *)(retx->data + i*retx->strides[0]) = xy.first;
685698
*(double *)(rety->data + i*rety->strides[0]) = xy.second;
686699
}
700+
701+
Py_XDECREF(x);
702+
Py_XDECREF(y);
687703

688704
Py::Tuple ret(2);
689705
ret[0] = Py::Object((PyObject*)retx);
690706
ret[1] = Py::Object((PyObject*)rety);
707+
Py_XDECREF(retx);
708+
Py_XDECREF(rety);
691709
return ret;
692710
}
693711

src/ft2font.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,18 @@ FT2Font::clear(const Py::Tuple & args) {
232232

233233
pen.x = 0;
234234
pen.y = 0;
235-
235+
236+
for (size_t i=0; i<glyphs.size(); i++) {
237+
FT_Done_Glyph( glyphs[i] );
238+
}
239+
240+
for (size_t i=0; i<gms.size(); i++) {
241+
Py_DECREF(gms[i]);
242+
}
243+
244+
glyphs.resize(0);
245+
gms.resize(0);
246+
236247
return Py::Object();
237248

238249
}

0 commit comments

Comments
 (0)