3

The reason I ask is because it is possible to operate on memory views in Cython without the GIL, and without somehow marking them to not be moved. For example:

def f(double[:] z):
    cdef int i, n = len(z)
    with nogil:
        for i in prange(n):
            z[i] += 1.5

This is unlike what happens in, for example, Java, where you have to get and release arrays in order to prevent them from being moved by the GC while you are using them in external code. So, either there is some marking or get/release thing going on behind the scenes, or else the Python garbage collector never moves arrays, which would seem to imply that the garbage collector is non-copying.

First of all, am I right that it is non-copying? And is this a guaranteed, documented feature of the language, meaning that anything that wants to call itself a "python interpreter" must have a non-copying garbage collector?

mrip
  • 14,913
  • 4
  • 40
  • 58
  • 4
    CPython's garbage collector only operates on cyclic references. It doesn't move anything in memory. – Martijn Pieters Apr 23 '16 at 18:30
  • Is that documented somewhere as part of the language specification, or is it "just the way it is"? – mrip Apr 23 '16 at 18:32
  • 2
    See the [CPython C-API documentation on memory management](https://docs.python.org/2/c-api/memory.html) and the [`gc` module](https://docs.python.org/2/library/gc.html). – Martijn Pieters Apr 23 '16 at 18:34
  • 2
    However, the behaviour of the CPython interpreter vis-a-vis memory is not standardised; each interpreter implementation can and does implement this differently. Jython uses the standard Java GC, IronPython the .NET CLR, PyPy certainly does it differently (they experiment with different approaches all the time). – Martijn Pieters Apr 23 '16 at 18:37

0 Answers0