Closed djsutherland closed 10 years ago
That code definitely needed cleaning up - thanks!
I bet this will fix: https://github.com/dbr/tvdb_api/issues/38 Will have to go run my tests again and report back
so far so good, tested 400 show lookups x3 times, no issues. still have to do the show.clear method otherwise the memory usage keeps growing. but no new issues found
The old code would end up doing effectively
del self._stack[0]; del self._stack[1]; del self._stack[2]
and so on. This isn't what was intended, since afterdel self._stack[0]
the thing that was previously 1 is now 0. This meant that the cache was being cleared incorrectly, and if there were a lot of things in the cache between GCs then you could get anIndexError
. It also moves the entire list around in memory over and over.Instead, we can just assign the variable to a sublist of the old one, which (a) doesn't crash and (b) takes one memory copy instead of
len(self._stack) - 100
.