utils: Make memoize() use a weakref for the first parameter
When used on methods, this avoids keeping a reference over the instances alive forever even when nothing else apart from the cache needs it anymore.
When used on methods, this avoids keeping a reference over the instances alive forever even when nothing else apart from the cache needs it anymore.