New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
frame.f_locals keeps references to things for too long #50366
Comments
When a frame's f_locals attribute is accessed, one of two things happens:
This means that the lifetime of locals in the frame is strangely altered The drawback of this is that references to locals may be "leaked" in a http://twistedmatrix.com/trac/ticket/3853 There, I suggested three possible solutions, in the form of a
pretend it would be automatically updated |
IMO, any of these three solutions should be accepted. |
Oh, I forgot dictionaries aren't weakrefable. That's such a pain, I Regarding the first solution, my only question right now is whether this |
I think the behaviour of f_locals can just be changed. |
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):
I want to add a fourth option to JP's initial ones:
What do you think? Regards, |
I think you misunderstood the bug report. The issue here is not that locals are referenced from the dict, it's that the dict is kept alive (since it is cached) longer that it should. By the way, reading the discussion again, I think we could simply make dicts weak-referenceable. A dict is already quite big in memory and I don't think adding a pointer to the struct would make a significant difference. |
I vote for option 1. We already eschew hacks with locals(). |
Antoine, to see if I understood correctly... if we build the dict, and just return it but don't save it in the frame, this leak would be solved? (yes, it'd be slower because everytime it's asked, it'd need to be built again) |
Le jeudi 05 mai 2011 à 18:45 +0000, Facundo Batista a écrit :
I would let Jean-Paul confirm the answer, but: yes. |
I tried making f_locals always a copy but it wreaks havoc with some code which expects changing it to "work", namely pdb. I resign myself to using weakrefs. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: