If the M5 firmware is close to the upstream MicroPython, you can:
And it will print the available free memeory
Will run the memory garbage collection to free up memory that is no longer being used. You can gc.collect() somewhere in your main loop to make sure memory is kept tidy.
See the gc module page for more information https://docs.micropython.org/en/latest/library/gc.html?highlight=gc#module-gc