How to switch windows for the lowest memory usage

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.


What MCU/Processor/Board and compiler are you using?

What LVGL version are you using?


What do you want to achieve?

What have you tried so far?

There are 2 lv_obj_t objects, A_screen and B_screen, the codes switch them by events as follows.But the system crashed after more 100 times switch. Is it memory leak?

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
}else if(event2)

## Screenshot and/or video
If possible, add screenshots and/or videos about the current state.

might not be a memory leak. It could be from memory fragmentation…

You can enable LV_USE_MEM_MONITOR in lv_conf.h to see the memory usage and fragmentation.

A typical issue is that styles should be lv_style_init()ed only once. If you do it in all the calls of ui_init()s the styles won’t be freed. Instead you can have a ui_style_init() function and initialize your styles there.

Question on this.

Would simply changing the “screen” cause more memory to be consumed? I would think that the screen that gets deactivated basically ends up with a recursive hidden being applied to it which would populate down to all of the children as well.

I would think that while it is not being used it still exists in the state it was originally in just not able to be seen or interacted with by the user. I would think that programmatically it can still be interacted with.

1 Like