Memory usage per top 10x usage per heapy
Oscar Benjamin
oscar.j.benjamin at gmail.com
Tue Sep 25 18:44:00 EDT 2012
On 25 September 2012 23:09, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Tue, Sep 25, 2012 at 12:17 PM, Oscar Benjamin
> <oscar.j.benjamin at gmail.com> wrote:
> > Also I think lambda functions might be able to keep the frame alive. Are
> > they by any chance being created in a function that is called in a loop?
>
> I'm pretty sure they don't. Closures don't keep a reference to the
> calling frame, only to the appropriate cellvars.
>
OK, that's good to know.
>
> Also note that whether a function is a closure has nothing to do with
> whether it was defined by a lambda or a def statement. In fact,
> there's no difference between functions created by one vs. the other,
> except that one has an interesting __name__ and the other does not.
> :-)
That's true but in my experience most lambda functions are defined inside
another function, whereas most ordinary functions are not. Also when
creating a closure with an ordinary function it's very clear what you are
doing (which is why I don't use lambda functions for this) so I think it's
a little easier to accidentally create a closure with a lambda function.
Oscar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120925/e30bfac0/attachment.html>
More information about the Python-list
mailing list