[issue6116] frame.f_locals keeps references to things for too long
Facundo Batista
report at bugs.python.org
Thu May 5 16:46:00 CEST 2011
Facundo Batista <facundo at taniquetil.com.ar> added the comment:
Making a copy of f_locals values to return a dictionary that doesn't hold references to the locals of the frame is not that simple (for me, at least):
- shallow copy: we'll return always a new dict, with the values being a copy of locals; this is simpler, but what about other objects that are referenced in in those values? For example, in locals exists a list A which holds a reference to object B; the new dict we return will have copy of A, but this copy will still reference B.
- deep copy: we'll return a new dict with a deep copy of all values; this is safer, but what about memory? In any case, how we could do a deep copy here? calling Python's code copy.deepcopy()?
I want to add a fourth option to JP's initial ones:
- have other attribute, something like f_locals_weak that is a list of tuples [(name, value), ...], being the values a weak reference to the real locals.
What do you think?
Regards,
----------
nosy: +facundobatista
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6116>
_______________________________________
More information about the Python-bugs-list
mailing list