https://toitlang.org/ logo
out of memory on PCB
# help
d
Hi, when running a Toit code on a PCB, i am getting an "allocation failed" error... see pls attached the error message ----------------------------------- this is the function where i get the error, is a simple post thru http to a web server: persist_data client data: e := catch --trace: response := client.post_json --host=URL --path=PATH { "data": data } data_response := json.decode_stream response.body print data_response response = null data_response = null if e: print "Error en POST: $e.stringify" any tip to free memory resources? thanks https://cdn.discordapp.com/attachments/1341126374651330621/1341126374898798612/malloc_error.txt?ex=67b4dcc4&is=67b38b44&hm=d41b624ca38076232b8124fb37a7131ff4b2b26e42a69d093eab16c261a6e97d&
f
It does look like an actual OOM
It's basically running out of memory when establishing the TLS connection.
Is there anything else running?
Independently, you could try to establish the connection earlier, when less memory is used. The really expensive part is establishing the connection. Once it exists you shouldn't need as much anymore.
Also, if you don't use BLE use the esp32-no-ble envelope. Just having BLE support reduces the amount of free memory.
d
after flashing the device with no-ble, as per your suggestiion... jag flash esp32-no-ble --name device1 im getting a different out of memory error... Heap report @ out of memory in primitive 6:2: ┌───────────┬──────────┬─────────────────────────────────────────────────────┐ │ Bytes │ Count │ Type │ ├───────────┼──────────┼─────────────────────────────────────────────────────┤ │ 45056 │ 13 │ toit processes │ │ 16384 │ 4 │ system 0 601fdfa0-55bf-adc8-1620-cf4dba25ce57 │ │ 20480 │ 5 │ other 1 af3508f3-fd45-adf5-a3d6-b140bf7705bd │ │ 8192 │ 2 │ current 4 42e2be1a-805a-b594-6e2a-f7a6f4a75a7d │ │ 335872 │ 1 │ heap metadata │ │ 4096 │ 1 │ spare new-space │ │ 8608 │ 6 │ heap overhead │ │ 216 │ 3 │ event source │ └───────────┴──────────┴─────────────────────────────────────────────────────┘ Total: 393848 bytes in 16 allocations (9%), largest free 3692k, total free 3707k ** Decoding by jag, device has version ** MALLOC_FAILED error. 0: Bus.test \i2c.toit:84:5 1: Bus.scan \i2c.toit:79:10 2: get-display get_display.toit:23:18 3: main lora_receive.toit:79:28 ** with the esp32-no-ble ... i get a malloc even before..
f
Are you sure this is the same program? The
get-display
call was in comments in the code you showed me.
@kasperl what is the heap metadata?
d
it is yes the same program, i commented the display lines to make it run.. sorry ive sent the code commented to you
k
Heap metadata is the extra bits we use to keep track of pointers in the heap. It is a percentage of the heap size.
Here the heap is pretty big, so we need a lot of space for the metadata.
f
Unless I'm misreading the data, the heap metadata is reported as 335872 bytes which is much more than the actual heap
k
What do you mean?
There is almost 4MB free in the heap?
Largest free block is 3692k.
f
Aah. I missed the k.
k
Important that one.
🙂
So we are very, very far from being out of memory for real.
Bus.test
is a write operation, no?
f
Ok. So switching to no-ble apparently also enabled spiram
It does small writes. Yes
k
If we fail for other reasons with the i2c writes, we still report out of memory which is kinda annoying.
Is that what we're hitting here?
f
Probably
k
So this is unlikely to actually be memory related.
f
I think we haven't released since we fixed it in the SDK ? Or was that just for the S3?
k
Like if
i2c_master_start
fails, we report out-of-memory.
f
@diego.ar try to remove the scan function in the get-display function
d
sure
k
When did we fix anything related to this?
d
by the way.. i made a small tweak on the get-display function.. since i was getting an error when using the gps and the screen on the same code..
f
And apparently you are using a wrover module, so is either esp32-spiram or no-ble, ... One that has external memory enabled
That's the one. I2C and external memory.
Exactly what's happening here.
k
Cool!
f
Removing the scan call should fix things
k
So we just need to build a test release and take it for a spin 🙂
d
just commented the code... //devices := bus.scan //if not devices.contains Ssd1306.I2C_ADDRESS: throw "No SSD1306 display found"
ill retry now
let me flash again on no-ble.. just a sec
running like a charm now...
error is gone
thank you very much for the support