Hello all,
I just wanted to share my experience with “style might be already inited (potentional memory leak)” issue when using lv_style_init(&style) and how I fixed it.
the issue was recalling lv_style_init() function every time I visit a screen, even if I switch the screen and come back it re initialize the style over and over again which cause holding space in memory, I tried using lv_style_reset but I didn’t work for me, when ever I call it the screen stays white and nothing happens.
the fix is pretty simple, all you need to do is:
1- create global lv_style_t variables
2-create a function that initialize the styles before loading any page( one time run)
for an example read this code:
#include "../../lv_demo.h"
//global style
static lv_style_t containerStyle1;
//call this function before loading any page
void initStyles() {
lv_style_init(&containerStyle1);
}
lv_obj_t* containerStyle(lv_obj_t* con) {
lv_color_t darkGreen = lv_color_hsv_to_rgb(182, 86, 11);//Background color
lv_style_set_bg_color(&containerStyle1, darkGreen);
lv_style_set_border_opa(&containerStyle1, 0);
lv_style_set_border_width(&containerStyle1, 2);
lv_style_set_radius(&containerStyle1, 0);
lv_obj_add_style(con, &containerStyle1, 0);
return con;
}
//function that creates a container object
void con (){
lv_obj_t* con = lv_obj_create(lv_scr_act());
containerStyle(con);
}
after trying this solution the style might be already inited (potentional memory leak) message disappeared from the log.
Hope that helps you guys.
Peace