dbr / tvdb_api

Simple to use interface to TheTVDB.com API in Python
The Unlicense
339 stars 63 forks source link

fix ShowContainer cache resizing #43

Closed djsutherland closed 10 years ago

djsutherland commented 10 years ago

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 after del 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 an IndexError. 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.

dbr commented 10 years ago

That code definitely needed cleaning up - thanks!

thezoggy commented 10 years ago

I bet this will fix: https://github.com/dbr/tvdb_api/issues/38 Will have to go run my tests again and report back

thezoggy commented 10 years ago

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