LVGL freezes after 6-7 minutes of run

Hi!
I’m totally new in LVGL and working with CYD ESP32. I have crafted simple application to show current weather and subway traffic. It works, but it freezes in 6-7 minutes after start, each time I run it.

I have read several topic and try to eliminate the issue, but no luck. What did I try?

  • create lv_styles only once (in setup method) and reuse them; (no luck)
  • output free memory into logs (do not notice any reduce of free memory during cycles)
  • output lot of print logs to find out the line where the freeze happens (fails on label creation it is always the same place)

I could not figure out the root cause of freeze. I hope I could find some advice here from experienced developers.

Here is my project.
The line project freezes is 548
I could not use standart logging approach with call back function for logging (project could not find method lv_log_register_print_cb, by the way what is the issue with it, could you advice?), so I use print as log output.

Any ideas why project freezes after several successful cycles and the same line?

Hello,

You check if the free memory reduces by checking the ESP heap. Are you sure you have configured LVGL to use your heap (by way of malloc)?

I think (fairly certain!) by default LVGL uses its own giant static array to allocate/deallocate “dynamic” memory. It could be that you are running out of this memory without it affecting your heap.

I figure that’s whats happening seeing as you call sl_metro_widget(departures, weather); every thirty seconds and you create new objects and initialize new styles every time!! This is not how you are supposed to use LVGL but let us first determine if the issue is really your memory.

You can do two things to test this:
First option is to set LV_USE_STDLIB_MALLOC to LV_STDLIB_CLIB in your lv_conf.h file, this will make LVGL use your heap, probably, I don’t know how ESP handles this.

I suggest the second option here:
set LV_USE_MEM_MONITOR to 1 and check the stats given here when you run your program. You also need to enable LV_USE_SYSMON for this setting to work.

Let me know if you find anything out,

Kind regards

@Tinus Hi! Thank you for help!

Let me check everything about the memory. I’ve been checking memor simple by output such log:
Serial.println(ESP.getFreeHeap());

You are correct every 30 seconds sl_metro_widget is doing rebuild. Styles are not the new one, they are reused, but all other objects are created from scratch - correct. May be here is the issues, but since I do not notice any descrease of value from ESP.getFreeHeap() I suggested it is not the case.

I will check that options and return back.

@Tinus I try everything you have suggested:

  1. defined options for monitoring in such way
#define LV_USE_SYSMON 1 /* added by me */

/*1: Show the used memory and the memory fragmentation
 * Requires LV_MEM_CUSTOM = 0*/
#define LV_USE_MEM_MONITOR 1 /*was before, swtiched to 1 */
#if LV_USE_MEM_MONITOR
    #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#endif

but do not see any new infromations in logs or anything. However, I’ve noticed that some config changes was not effective before as well, so may be this flags were not picked for some reason. What extra infromation should I expect and where I could find that?

  1. Setup a new flag:
#define LV_USE_STDLIB_MALLOC LV_STDLIB_CLIB

Also do not notice any changes except the fact free heap amount starts to slowly decreasing over iterations. I’m tracking it via code Serial.println(ESP.getFreeHeap());

Free heap starts 174396 and was descreasing to 173740 until the app freezes.

Not sure if I apply all options in correct way. Could you advise?

Another way to go, I’m thinking about - is to create all UI elements once during init section and only amend text over each iteration. Not sure if that is a root cause, but it could be helpful.

Hello,

I did not realize you were using LVGL 8.4, the configuration options I sent you were for for V9.

You should set LV_MEM_CUSTOM to 1, and you will most likely see your heap get smaller.

If you want to see how much memory you are using, set LV_MEM_CUSTOM to 0 and simply enable LV_USE_MEM_MONITOR. This does not work in conjunction with reading the free heap. Again I recommend doing this.

Yes, you should most definitely do that. I do not know if this is the root cause either because we haven’t been able to tell memory usage. But LVGL will definitely run out of memory the way you are doing it now. You are currently constantly creating new objects without erasing the old ones- basically a giant memory leak.