[pypy-dev] Locals clearing in RPython

Timothy Baldridge tbaldridge at gmail.com
Thu Sep 6 19:46:19 CEST 2012


Let's imagine that I have some code like the following in RPython:


def wrapper_func(arg1, arg2):
    return inner_func(arg2)

def inner_func(x):
   for y in range(x):
      # do something here
      pass
   return -1

bigint = 1000000

wrapper_func(list(range(bigint)), bigint)

The problem here is that arg1 is going to be held onto in (in CPython at
least) until inner_func returns. This means that the list created on the
invocation of wrapper_func is going to stick around during the entire
execution time of inner_func. This would not make much of a difference
normally, but in languages with extensive use of lazy evaluation, holding
onto the head of a sequence could cause out-of-memory errors. In Clojure
this is fixed-up by the compiler via "locals clearing". Basically the
compiler inserts "arg1 = None" before the invocation of inner_func.

What's the story here in RPython? Since RPython basically compiles down to
single-assignment code I'm guessing the Clojure fix won't help me. When is
the GC able to go and free data held by arguments?



Timothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120906/abe38a76/attachment.html>


More information about the pypy-dev mailing list