On Fri, 2020-09-25 at 18:19 +0200, Marco Sulla wrote:That I hope it's not the place where this proposal will be sent.My idea is apparently simple: what if, anytime we create an object,instead of deleting it, we send it in a trash bin? If the object is,for some reason, recreated, we can take it from the trash bin. Ifthere is no more memory, the trash bin will be empty.The problem is that, probably, args and kwargs used by object creationmust be stored. Maybe also copied? This could slow down the objectcreation instead of speed it up? Could this be done by a separatethread?This would assume that said objects: a) are immutable and b) initialize to identical values for a given *args and **kwargs.
And if that's true, then the OP's purpose could be served by a
function that uses collections.lru_cache() to generate their
objects. The arguments would also have to be hashable, but if
they're immutable then hashable is easy.