Hello Vikas,
in your implementation you create a new string by invoking the function EwNewString() or EwNewStringUtf8(). First at all, this is the right approach. The disposal of the memory occupied by the strings is performed during the garbage collection. This operation is triggered at the end of the screen update (see step 7 in chapter Platform Integration Aspects: Main Loop). Consequently, when you create a string and switch the screen, the string continues occupying the memory until the garbage collection is performed.
The garbage collection (as its name indicates) reclaims only 'garbage'. The string is considered as garbage when there is no variable, property, etc. in the GUI application referring the string. When the string returned by the method GetAppName() is assigned to e.g. a Text view and the view belongs to an actually used object, the string can't be discarded - it is actively used - at least from the garbage collection's point of view.
I am wondering if each time user moves to the screen which calls this function, the new memory gets allocated but might not be freed until the end of EW task.
Possibly your application creates more and more objects and connects them together so all the objects are in use? To test it I would recommend following approaches:
1. When you prototype your application in Embedded Wizard Studio, you can track the RAM usage. See: Embedded Wizard Studio: Memory (RAM) usage window. Please note the explanation in the referenced chapter concerning the frequency when the garbage collection is started during the prototyping. Misunderstanding this aspect may lead to wrong memory usage interpretation. With this debug window you can observe how many objects exist and whether the number increases.
2. In the target system you can protocol the memory usage. For this purpose the function EwPrintProfilerStatistic() is available. Each time you invoke the function a short overview of the actual memory usage, the number of objects and number strings is printed on the console. Depending on your target system, it may be sufficient to rebuilt your application with the defined macro EW_PRINT_MEMORY_USAGE. See also the section Monitoring the Data Memory (RAM) usage. Again, the outputs help you to track whether the number of objects/string increases or not.
I hope it helps you further.
Best regards
Paul Banach