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

Damien George damien.p.george at gmail.com
Mon Oct 12 11:06:07 CEST 2015


I didn't turn on finalisers because from experience they are rarely
needed.  But they are not expensive to turn on so we can if needed.

__del__ goes in the dict_table.

I think we should fix this properly instead of monkey patching here
and there.  Properly means combining the 2 heaps (uPy GC and C++).
This would also give more RAM overall because then there's not a hard,
fixed barrier between the 2 heaps which is currently 9.5k and 2k.


On Mon, Oct 12, 2015 at 9:57 AM, Larry Hastings <larry at hastings.org> wrote:
> On 10/12/2015 01:53 AM, Damien George wrote:
>
> 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.
>
>
> I'm guessing there's a reason you didn't turn on finalisers for the
> micro:bit build though.  Why not?
>
> Does __del__ go in the dict_table, or is it a member of the type?
>
>
> 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".
>
>
> Aha!  So that explains why I was only able to create 50 or so Image objects
> before I got an 020.  The Image constructor calls new MicroBitImage and
> there is no matching delete.
>
> Is that really how we want to live our lives?
>
>
> /arry
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list