[Microbit-Python] Memory leak in print or string formatting

Damien George damien.p.george at gmail.com
Thu Jan 7 18:32:31 EST 2016


Thanks for the bug report on this memory error.  I tracked it down to
string data not being zero'd out on initialisation (and hence keeping
a pointer around which prevented the GC from reclaiming some memory,
but in a very pathological way where all previous strings that were
created with str.format were linked in a chain).

A fix will appear soon.

On Thu, Jan 7, 2016 at 12:18 PM, Tom Viner <tom at viner.tv> wrote:
> Yeah I've also had MemoryErrors with .format() too. In my case I was
> formatting floats though.
>
> If it's helpful I can try to find a minimal test case.
>
> As for the memory error, I experimented a bit. Turns out that
> both %- and .format() formatting cause the problem, but not
> necessarily in the same way, e.g. the attached script
> runs fine (at least more than 1000 iterations) when using
> the %-formatting code, but fails with a MemoryError at
> offset 409 with the .format() approach:
>
>         print ('Offset: %i' % offset)
> vs.
>         print ('Offset: {}'.format(offset))
>
> What's interesting is that when you change the display logic
> from:
>
> display_leds = display_leds_set_pixel
>
> to
>
> display_leds = display_leds_image_array
>
> The memory leak appears to go away.
>
> PS: I'm currently experimenting with the fastest way to display
> a list of lists on the LEDs.
>
> Cheers,
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Experts (#1, Jan 06 2016)
>>>> Python Projects, Coaching and Consulting ...  http://www.egenix.com/
>>>> Python Database Interfaces ...           http://products.egenix.com/
>>>> Plone/Zope Database Interfaces ...           http://zope.egenix.com/
> ________________________________________________________________________
>
> ::: We implement business ideas - efficiently in both time and costs :::
>
>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>            Registered at Amtsgericht Duesseldorf: HRB 46611
>                http://www.egenix.com/company/contact/
>                       http://www.malemburg.com/
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
>
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>


More information about the Microbit mailing list