Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    MEmoryError: memory allocation failed

    Scheduled Pinned Locked Moved LoPy
    lopymemoryerror
    2 Posts 2 Posters 495 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      AHellLycan
      last edited by

      Re: [MemoryError: memory allocation failed](allocating 2048 bytes - LOPY - 1.2.0.b1)

      Hello, I have this error too, but I want to know if this can work when the error comes out in the execution time, not the compilation, or how can I fix that.

      Thanks in Advance

      C 1 Reply Last reply Reply Quote 0
      • C Offline
        crumble @AHellLycan
        last edited by

        Depends.

        2k on a LoPy is a lot of memory. If it occurs during compilation time, precompiling your code with mpy_cross is the solution.

        Otherwise it is not that easy. You have to reduce memory fragmentation.
        You can see the fragmentation with micropython.mem_info()
        Precompile as many files as you can. So the memory of the LoPy is not fragmented after boot time. Allocate huge buffers as early as you can. Reuse them instead of reallocate.

        You can try to call the garbage collector in front of your memory allocation. But this does not help in many situations. The garbage collector does not relocated objects in use, so the memory is still fragmented. If there is a background thread, it may fill your memory faster than you can free it. For example if it calculate float objects in a loop.

        1 Reply Last reply Reply Quote 1

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom