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

Mark Shannon mark at hotpy.org
Mon Oct 12 10:19:08 CEST 2015


Any Python objects that allocate memory on the C++ heap are just 
trouble. Explicitly freeing them in the finalizer would mostly work, but 
it is expensive and error prone. It is much better to make sure that we 
don't use malloc and/or new in any objects in the first place.

I've got a PR that fixes Image and the display, but there other cases 
where this still happens.

Mark.

On 12/10/15 08:08, Larry Hastings 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