I have a severe memory issue (on both iOS and Android, but mostly concerned about iOS at the moment) whenever my app navigates to and from the home page. In the attached image, the peaks are generally whenever the app lands on the home page and the valleys after the dips are when I go to a different page.
The reason why the home page is so bloated is because it has several components nested inside it, some of which pull images and other data from online resources. I also pass data through services between components within the home page and pages being navigated to from the home page. However, any data that is directly observed is unsubscribed upon unloading the page.
I’ve been doing a lot of research and trying to implement different solutions such as the following:
- Manually calling the garbage collector ( GC() ).
- Using web-image-cache for web images and calling clearCache() upon navigating away from the page.
However, those solutions haven’t done much to decrease my memory usage. I’m currently looking in to changing my router from RouterExtensions (from nativescript-angular/router) to
router-outlet based on the discussion in this thread and the docs, as well as going through my code and eliminating unnecessary view nesting and general optimization. Despite having a general direction, I have some questions that I was hoping can be answered:
Are these memory issues being caused by image caching, route caching, suboptimal view nesting, or a combination of all 3? I would’ve assumed that it was primarily caused by image caching and route caching, since my memory usage does not decrease upon navigating away from the home page.
How effective at reducing memory usage would optimizing my views be? As stated above, I didn’t think that memory usage would be improved by optimizing my views, but I recognize that there would be some performance improvements.
What would be the best solution to avoid my memory issues? Again, I haven’t tested the router solution yet, but in the case that it doesn’t work out, I’m really hoping for another lead.
Thanks for reading this, and I hope to hear any potential suggestions.