Good morning,
I have the following issue with memory management.
I am using an ESP32-WROVER, and I have 4MB of RAM available on the device.
I have currently configured Embedded Wizard GUI as follows:
EW_USE_PSRAM 0x157C00 // 1,408,000 Kbytes as EW_MEMORY_POOL_SIZE
#define EW_USE_IMMEDIATE_GARBAGE_COLLECTION
#define EW_MAX_STRING_CACHE_SIZE 0
#define EW_MAX_SURFACE_CACHE_SIZE 0
#define EW_MAX_GLYPH_SURFACE_WIDTH 256
#define EW_MAX_GLYPH_SURFACE_HEIGHT 256
#define EW_MAX_ISSUE_TASKS 80
#define EW_LAZY_LOAD_BITMAPS 1
#define EW_LAZY_LOAD_BITMAPS_IF_ANIMATED_ONLY 1
#define EW_DISCARD_BITMAPS 1
#define EW_DISCARD_BITMAPS_IF_ANIMATED_ONLY 1
#define EW_DISCARD_BITMAPS_IF_NOT_USED_IN_CURRENT_UPDATE 0
#define EW_DISCARD_BITMAPS_IF_NOT_USED_IN_RECENT_UPDATES 0
#define EW_CACHE_OFFSCREEN_SURFACES 0
Everything works perfectly, but the problem arises when I use EwLoadExternBitmap in specific situations.
The problem in detail:
If I load for example an image of 695 × 480 × 3 = 980 KB, using:
bitmap = EwCreateBitmap( EW_PIXEL_FORMAT_NATIVE, frameSize, 0, 1 );
The operation is successful, the graphics work perfectly, and I can correctly render the image: Even when I implement an image carousel, continuously changing EwLoadExternBitmap, everything works fine.
However, the issue occurs when the Device Driver requests the GUI to reload the same page. In this phase I recall the page (pagetoreload for example) with:
this.PresentDialog(pagetoReload, null, null, null, null, null, null, null, null, false);
But when the code reaches:
bitmap = EwCreateBitmap( EW_PIXEL_FORMAT_NATIVE, frameSize, 0, 1 );
There is not enough memory available!! So, I don't understand why!??
Using the function:
EwPrintProfilerStatistic(1);
I can see that the page "pagetoReload" is loaded twice into memory (and so probably the previous bitmap is still stored in the EW_MEMORY_POOL_SIZE). As a result, I run out of RAM, and of course, the call to EwCreateBitmap( EW_PIXEL_FORMAT_NATIVE, frameSize, 0, 1 ) fails.
What I have tried:
- Using SwitchToDialog instead of PresentDialog However, EwPrintProfilerStatistic(1) still shows two instances of the "pagetoReload" page in RAM, and EwCreateBitmap() fails.
- Calling DismissDialog before PresentDialog, in this case, the UI crashes.
- Calling EwReclaimMemory(); before this.PresentDialog: Unfortunately, this did not improve the situation.
I do not understand why the page is duplicated in memory.
Unfortunately, I cannot increase the RAM because I am already at the limit.
Is there anything I can do to free the previous page properly before loading a new one?
Thank you in advance.