From: Raymond Hettinger Date: Sat, 8 Nov 2003 11:58:44 +0000 (+0000) Subject: Improve the reverse list iterator to free memory as soon as the iterator X-Git-Tag: v2.4a1~1315 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=001f228f369d5c3e9fc28ae7a9815e1317bbe72f;p=thirdparty%2FPython%2Fcpython.git Improve the reverse list iterator to free memory as soon as the iterator is exhausted. --- diff --git a/Objects/listobject.c b/Objects/listobject.c index 7198e3481afc..3782c3baacfd 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2771,7 +2771,7 @@ PyTypeObject PyListIter_Type = { typedef struct { PyObject_HEAD long it_index; - PyListObject *it_seq; + PyListObject *it_seq; /* Set to NULL when iterator is exhausted */ } listreviterobject; PyTypeObject PyListRevIter_Type; @@ -2819,6 +2819,9 @@ listreviter_next(listreviterobject *it) item = PyList_GET_ITEM(it->it_seq, it->it_index); it->it_index--; Py_INCREF(item); + } else if (it->it_seq != NULL) { + Py_DECREF(it->it_seq); + it->it_seq = NULL; } return item; }