Joe wrote:
> Hello John and other devels,
>
> John, you were right on the money in relation to the memory leak that I wrote
> about in the previous message. Here's a rough draft of an attempt to patch
> that up. This is my first (meaningful) attempt to submit a patch anywhere,
> so please forgive any errors in the process. It was made with >patch -p ...
> I think that is the accepted way to make a patch, but I'm not sure.
> *** text.py Tue Jan 18 21:03:16 2005
> --- /root/text.py Tue Jan 18 20:58:56 2005
> *************** class Text(Artist):
> *** 44,49 ****
> --- 44,50 ----
>
> Artist.__init__(self)
> self.cached = {}
> + self.usage_stack = []
> self._x, self._y = x, y
>
> if color is None: color = rcParams['text.color']
> *************** class Text(Artist):
> *** 193,198 ****
> --- 194,203 ----
>
> ret = bbox, zip(lines, whs, xs, ys)
> self.cached[key] = ret
> + self.usage_stack.insert(0, key)
> + if len(self.usage_stack) > 128:
> + self.usage_stack.pop()
> + del self.cached[key]
> return ret
Just a minor comment: insert(0) is an expensive (O(N)) operation on lists.
This kind of problem might be better addressed with a deque
(http://www.python.org/dev/doc/devel/lib/module-collections.html, could be
backported to py2.3).
Cheers,
f
|