Description
Right now tzoffset
, tzstr
and tz.gettz
each retain strong references to every unique time zone ever constructed by that method. I think in the end this will be a net savings in memory in most use cases since it prevents duplication of time zones, but it could also cause a huge proliferation of memory in applications that make short-lived references to a large number of time zones (since those time zones, when they go out of scope, would normally get garbage collected).
In Python 3 there is the weakref module, which allows the creation of weak references, such that an object will be garbage collected if only weak references to it exist.
Rather than try and use backports.weakref
in Python 2, I think we can just write a "pass through" compatibility shim that has the same external form as weakref
but simply holds a strong reference to the object in question.