I’m trying to debug a heap memory allocation failure.
Traceback (most recent call last):
File "<stdin>", line 29, in <module>
MemoryError: memory allocation failed, allocating 76 bytes
Here are 3 tests:
TEST 1: Baseline
import gc
import time
import urandom
import lvgl as lv
import ILI9341 as ili
import lvesp32
# Initialize the ILI9341 driver
# spihost: 1=HSPI 2=VSPI
# display has exclusive use of this SPI bus
disp = ili.display(spihost=2, miso=19, mosi=23, clk=18, cs=5, dc=21, rst=4, backlight=22, mhz=40, share=ili.EXCLUSIVE)
disp.init()
# Register display driver to LittlevGL
disp_buf1 = lv.disp_buf_t()
buf1_1 = bytearray(480*10)
lv.disp_buf_init(disp_buf1,buf1_1, None, len(buf1_1)//4)
disp_drv = lv.disp_drv_t()
lv.disp_drv_init(disp_drv)
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = disp.flush
disp_drv.hor_res = 320
disp_drv.ver_res = 240
disp_drv.rotated = 0
lv.disp_drv_register(disp_drv)
while True:
print('1',gc.mem_free())
screen = lv.obj()
print('2',gc.mem_free())
l = [urandom.random(), urandom.random()]
print('3',gc.mem_free(),'\n')
time.sleep_ms(1)
gc.collect()
The GC output shows that the heap allocation is not freed. Eventually, allocation failure happens.
1 99664
2 99568
3 99504
1 99568
2 99472
3 99408
TEST 2: comment out "screen = lv.obj()"
import gc
import time
import urandom
import lvgl as lv
import ILI9341 as ili
import lvesp32
# Initialize the ILI9341 driver
# spihost: 1=HSPI 2=VSPI
# display has exclusive use of this SPI bus
disp = ili.display(spihost=2, miso=19, mosi=23, clk=18, cs=5, dc=21, rst=4, backlight=22, mhz=40, share=ili.EXCLUSIVE)
disp.init()
# Register display driver to LittlevGL
disp_buf1 = lv.disp_buf_t()
buf1_1 = bytearray(480*10)
lv.disp_buf_init(disp_buf1,buf1_1, None, len(buf1_1)//4)
disp_drv = lv.disp_drv_t()
lv.disp_drv_init(disp_drv)
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = disp.flush
disp_drv.hor_res = 320
disp_drv.ver_res = 240
disp_drv.rotated = 0
lv.disp_drv_register(disp_drv)
while True:
print('1',gc.mem_free())
#screen = lv.obj()
print('2',gc.mem_free())
l = [urandom.random(), urandom.random()]
print('3',gc.mem_free(),'\n')
time.sleep_ms(1)
gc.collect()
The GC output shows that the heap does not change size
1 104768
2 104768
3 104704
1 104768
2 104768
3 104704
TEST 3: comment out driver registration
import gc
import time
import urandom
import lvgl as lv
import ILI9341 as ili
import lvesp32
# Initialize the ILI9341 driver
# spihost: 1=HSPI 2=VSPI
# display has exclusive use of this SPI bus
disp = ili.display(spihost=2, miso=19, mosi=23, clk=18, cs=5, dc=21, rst=4, backlight=22, mhz=40, share=ili.EXCLUSIVE)
disp.init()
'''
# Register display driver to LittlevGL
disp_buf1 = lv.disp_buf_t()
buf1_1 = bytearray(480*10)
lv.disp_buf_init(disp_buf1,buf1_1, None, len(buf1_1)//4)
disp_drv = lv.disp_drv_t()
lv.disp_drv_init(disp_drv)
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = disp.flush
disp_drv.hor_res = 320
disp_drv.ver_res = 240
disp_drv.rotated = 0
lv.disp_drv_register(disp_drv)
'''
while True:
print('1',gc.mem_free())
screen = lv.obj()
print('2',gc.mem_free())
l = [urandom.random(), urandom.random()]
print('3',gc.mem_free(),'\n')
time.sleep_ms(1)
gc.collect()
The GC output shows that the heap does not change size
1 110576
2 110560
3 110496
1 110576
2 110560
3 110496
Does anyone have an insight into this behavior? Perhaps I don’t have the driver registration correctly configured?