Bug: Running out of memory, fix/cut things loading up into memory #22
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
alright i got this error after trying to temp hold new settings:
Error loading page
memory allocation failed, allocating 14032 bytes
from log:
The fix for now:
So i'm thinkin soon i will run out of memory/ram. It would be light weight to just code in an api and have a server/pc link to the pi.
Will need to host html files on local computer/server in order to view web page configurations. It's just too much to put on a pico with 250kb of ram. 70kb to load current full application. Not quite sure how to break it down I just think python loads into memory/ram and then runs from there. Once i figure out the way around it could be less restrictive
Pico W Memory Specs:
RAM (SRAM):
Total: 264 KB (264,192 bytes)
Available for MicroPython: ~190-220 KB (rest used by system)
Your current usage: Generating 14KB HTML pages + all your code/objects
Flash Storage:
Total: 2 MB
Used for: MicroPython firmware (~1.4 MB) + your scripts + config files
Available: ~600 KB for your code
Why You're Running Out of RAM:
When generating a page, Python must:
Load the entire HTML template
Format it with variables
Convert to bytes
Send chunks over socket
Problem: The string exists in memory 2-3 times during this process!
MicroPython's GC doesn't run automatically as often as CPython. You need to manually call gc.collect() frequently.
Memory Saving Solutions:
Immediate Fixes (Already Done):
✅ Added gc.collect() before page generation
✅ Minified HTML (removed whitespace)
Additional Optimizations Needed:
Web Server Optimization - Stream HTML Instead of Building Full String:
Reduce Config Storage:
Remove extra whitespace - saves a few bytes when loaded into RAM.
Quick Memory Check Command:
Add this to see what's using memory:
Bottom Line:
Pico W has ~220KB usable RAM, and you're:
Using ~100KB for code/objects
Using ~14KB for each HTML page generation
Leaving ~100KB free (barely enough)
Solutions in order of priority:
✅ Call gc.collect() more often (every 5 seconds)
Consider splitting settings into smaller pages (less HTML per page)
Use chunked transfer encoding for HTML (advanced)
Remove auto-refresh or increase to 60 seconds (less frequent page loads)
For now, the gc.collect() fix should hold, but if you add more features, you'll need chunked HTML streaming.
So we are loading a lot at the top of main.py
Feature: move web page to server and code in apito Bug: Running out of memory, fix/cut things loading up into memory