[Microbit-Python] How does GC work in micro:bit MicroPython?

Damien George damien.p.george at gmail.com
Mon Oct 12 10:53:49 CEST 2015


Finalisers are supported by MicroPython (although not enabled in the
microbit version but that's a 1 line config change), your (C) type
just needs to define the __del__ method.

To trace live objects the GC starts at the root pointers.  These are:
stack, registers, micropython state (mp_state_ctx object, see
inc/py/mpconfig.h) and the port-specific root pointers defined in
inc/microbit/mpconfigport.h, line 99 (search for
MICROPY_PORT_ROOT_POINTERS).

It is a problem that we have a separate C++ heap and it should be
combined into the micropython GC heap.  Because at the moment it's not
possible to reclaim stuff allocated using the C++ "new" keyword.
Unless you write a finaliser and do a "delete".

On Mon, Oct 12, 2015 at 8:08 AM, Larry Hastings <larry at hastings.org> wrote:
>
>
> I don't see any registration for gc finalizers.  No __del__ anywhere.  So
> how do objects get cleaned up?
>
> For example, the constructor for microbit.Image creates a "new
> MicroBitImage()" object.  Where is this object deleted?
>
> Does it just walk the entire heap, use a heuristic to find things that
> "look" like pointers, and recycle anything that it believes isn't reachable?
>
>
> /arry
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list