Closed dimakuz closed 7 years ago
@beregond , take a look please
@dimakuz looks nice. How did you run into memory leak with weak key dictionary?
@beregond
I did not run into memory leak, but there is a stack overflow due to infinite recursion in __eq__
if we don't use cache keys.
This happens because in __eq__
if types are the same and we go on to compare field values, we have to lookup in dict (Field.memory
) with object itself as key, this access calls __hash__
and __eq__
on object and thus we have an infinite recursion
Ok, nice idea with CacheKey
object!
Released in 2.1.4
This patch adds the ability to compare model instances based on their type and fields (rather than their reference).
This patch also adds
_cache_key
member and changesField.memory
access to be byobj._cache_key
rather thanobj
itself. This had to be done because memory's__getitem__
called obj's__eq__
and caused stack overflow.