Memory Issue on Android and iOS



Hi all,

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:

  1. Manually calling the garbage collector ( GC() ).
  2. 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:

  1. 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.

  2. 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.

  3. 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.


I am not sure if this has to do with your app. I have noticed a lot of leaks in the default Hello World app as well. I put up the recording here: You can check the description for info.


Hey @pentool, thanks for the response. That might be related to my issue, but after commenting out chunks of my HTML and seeing which components were causing memory leakages, I’ve found that trying to declare positional variables by waiting for the page to load was causing the issue. For example, there were some absolute layout variables that were being calculated after certain elements were loaded, but after refactoring those variables to be based on the screen width and height, there is significantly less build-up in memory.


The Instruments tool memory leak detection might be misled by a NativeScript iOS application. In a pure iOS application, when navigating back, native objects are immediately released. In a NativeScript iOS application native objects are released as soon as their JavaScript counterparts are garbage collected. Since the JavaScriptCore garbage collection fires randomly and cannot be predicted, the Instruments panel may raise false memory leak alarms.

Can you share some more details on the steps you were taking in the NativeScript app to shoot the video you have posted?

Memory leaks in basic "Hello World" app...?