heap_unlock() returning MemoryError

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
lowkey_daisy
Posts: 12
Joined: Tue Apr 14, 2020 6:08 pm

heap_unlock() returning MemoryError

Post by lowkey_daisy » Sun May 31, 2020 11:27 pm

Hi!

I'm not sure if this is an error or I'm just doing crazy stuff, but when I lock the heap and unlock it right after, this last command returns a MemoryError, like this:

download/file.php?mode=view&id=1052

I'm using the micropython Unix port, where I'm trying to force an Out of Memory error to test my failsafe. Is this a bug?

Thank you!
Attachments
micropython_bug.png
micropython_bug.png (20.43 KiB) Viewed 182 times

User avatar
dhylands
Posts: 3385
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: heap_unlock() returning MemoryError

Post by dhylands » Mon Jun 01, 2020 5:00 am

I wouldn't trust the results when issuing the command from the REPL. To test it properly, put it in a function and call the function from the command line.

The REPL keeps command history, and the act of typing ANY command will cause memory allocation to occur from the REPL. The REPL also stores the result from the last command executed which it stores in a variable.

lowkey_daisy
Posts: 12
Joined: Tue Apr 14, 2020 6:08 pm

Re: heap_unlock() returning MemoryError

Post by lowkey_daisy » Mon Jun 01, 2020 9:40 am

You're right, it worked :D

Thank you for the help!

User avatar
dhylands
Posts: 3385
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: heap_unlock() returning MemoryError

Post by dhylands » Mon Jun 01, 2020 3:54 pm

This also seems to just be an issue on the unix port. The embedded ports have got which detect if the heap is locked when entering the REPL and will automatically unlock it.
https://github.com/micropython/micropyt ... #L468-L472

Post Reply