On Saturday, October 8, 2016 at 12:12:30 PM UTC-7, Nils Bruin wrote:
>
> On Saturday, October 8, 2016 at 8:43:33 AM UTC-7, John H Palmieri wrote:
>>
>>
>> What are all of the drawbacks?
>>
>> The ones I am aware of:
> - the construction parameters need to be cached. That might have lifetime
> implications for them.
>
A particularly devious one is this:
class A(...):
...
@cached_method
def B(self):
return Bclass(self)
class Bclass(UniqueRepresentation):
...
a=A(...)
b=a.B()
del a,b
This creates a memory leak (a and b will never be deallocated).
Thanks to UniqueRepresentation, b lives in a global WeakValueDict, keyed
by a (so a will live as long as b will live). Conversely, because a.B is
cached, it will have a reference to b, so a will keep b alive. Hence, a
reference loop anchored in a global object.
As soon as UniqueRepresentation is involved anywhere, you have to be very
careful about caching. The weak global reference that exists for
UniqueRepresentation to function is very easy to short-circuit into a
reference cycle that prevents deletion.
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.