Memory leaks while using UI Builder

Hello all,

I’m new to wearables and to Tizen Studio. Started developing some apps for Galaxy Watch recently.

Tried to use UI Builder-Navigation View image to create Native App.

Then after using the app for some time it started crashing. I have found out that it was because of high usage of memory.

Started to dig into this and turned out there were some leaks in files generated by UI Builder.
Even initial application created by UI Builder has the leaks - tested with Leak Sanitizer.
(Of course not only this, sample Previous button was actually creating new view and pushing it to Elm_Naviframe instead popping old view)

So then I tried freeing the memory that was allocated in generated uib_view_create() function (managed/src/view/) and not freed anywhere before.
Turned out that there is still managed/manager/uib_view_manager.c that holds the pointers to views contexts that I’ve freed and got a crash obviously.
The generated files are unable to modify, since:

/*******************************************************************************

  • This file was generated by UI Builder.
  • This file will be auto-generated each and everytime you save your project.
  • Do not hand edit this file.
    ********************************************************************************/

So here is my story :wink:

Do you have any advice here? Is there a way to use UI builder and maintain the leaks?

Thanks!

Hi,
To produce leak in a application and use leak sanitizer to find it:

  1. create a service application using 4.0 templates in Tizen Studio
  2. you can introduce any leak example by below code
    char* ptr1 = (char *) malloc (10);
  3. Run leak sanitizer by doing profile as -> Leak Sanitizer.

Note: The Memory Leaks are visible only on terminating the application. open the emulator , click back button to make the application go in the background(it will still not be terminated), then after opening the list the installed app’s you can long press on the app’s icon and uninstall it to ensure that the running app will be terminated.

Then automatically the Memory Errors window will be visible and the leak will be seen.

Thanks.

Thanks for your reply!
However it’s not addressing my question, maybe I was not clear enough…

I do know how to produce leaks on purpose, if I ever would need to.
I also know how to use Leak Sanitizer, but thanks for describing it, so others can use it as well!

Then again the problem is: The code generated by UI Builder has memory leaks
If you check the code that is generated by UI Builder, you will see uib_view_NAME_create() function (file src/managed/src/uib_NAME_view.c) allocs memory for view context (calloc). The memory is never freed in any generated code.

If you simply try to free the memory in event handler (editable file src/event_handler/uib_NAME_view_event_handler.c) in NAME_onuib_view_create() function then next time you want to use the same view, it will end up crashing in generated find_view_context() function (uib_view_manager.c) which still tries to use the pointer to already freed context.

The workaround for this is using the fact that uib_view_manager.c overrides the view context pointer for each view creation (that has the same name). To get rid of memory leaks I simply keep the previous context pointer (in editable event handler code) and I free it after new one is created , so I have only one context allocated at the time.

But I’d say that is still only a workaround…

What I’d like to know is how to make UI Builder to not generate code with memory leaks?
Or is there any better way to handle it maybe?

@SNS_1205, you can see what I mean by creating simple UI Builder -Navigation View (Wearable v4.0) template project and running Leak Sanitizer towards it.

Thanks!