ios
ios copied to clipboard
Navigate Memory Problem
I am running into a reproducible memory leak that occurs when navigating to another page. In my example we navigate with a 1 second timeout to the same page in an endless loop.
Example Repository: https://github.com/atabix/nativescript-memory-leak-example
➜ nativescript -v
7.2.0
Use Case 1
Run the app with all of the same dependencies with one exception: @nativescript/[email protected]
Allow the app to run for a period of thirty minutes.
Use Case 2
Run the app with all of the same dependencies with one exception: @nativescript/[email protected]
Allow the app to run for a period of thirty minutes.
Results
The app starts around ~74MB in both uses cases. In this first couple of minutes the app slowly increases in total memory used, incrementing about 1MB every couple of seconds.
After this initial period the memory seems to stabilize at around 93MB.
The same test has been applied to two very different apps in production with pages that are more complex. This example here resulted in 1MB increments. The production apps resulted in 50MB increments (starting at 146MB and eventually reaching 2GB). In combination with navigating between different kinds of pages this memory problem is compounded, eventually resulting in the app shutting itself down.
This behavior remained consistent when manually calling Utils.GC()
and using clearHistory: true
on navigation. These two seemed to have no affect on the outcome of the results.
Honorable mention
The issue was first discovered in a project using nativescript-vue. The funny thing is that the amount of memory in each increment used is less than vanilla NativeScript. To remove nativescript-vue as a variable the above uses cases have taken place without it.
References
https://github.com/NativeScript/NativeScript/issues/6890
- Manual garbage collection doesn't resolve the issue.
https://github.com/NativeScript/nativescript-angular/issues/1215
- The issue seems to be with Angular. A similar approach was attempted for NativeScript Vue by hooking into the destroy method of Vue components; however, as mentioned above, Vue doesn't seem to be a factor in this problem.
https://github.com/NativeScript/ns-v8ios-runtime/issues/100
- This is currently an issue in the v7.2.0 iOS runtime. Perhaps it may also be affecting other factors of NativeScript?
I am currently at a loss as to how to proceed. The issue is extremely significant in any pages that display more than a single button and some text. It's only apparent in apps where people navigate between pages a lot for an extended period of time.
Thanks @brysem,
Did you find a solution to this issue?
We are experiencing the same problem for both IOS Runtime and IOS V8 Runtime when navigating between pages. The issue is only on IOS and the profiling we have done on Android shows continuous memory management by the GC. We will post an issue with a detailed explanation of the memory problems we are seeing, although they are the same as the ones you have experienced. I am unsure how any IOS app, with more than one page, is performing given the memory keeps growing till the app crashes.
Hi @johnmcauley,
I have not yet. I will start debugging the runtime myself this week. The v7.2.0 runtime has a compounded issue in which promises are leaking memory too.
I would prefer to debug v6.5.4 because the promise problem is not present. However, I can't find a commit, tag or reference to this version of the runtime in this repository. @rigor789, do you know where I can find this?
Debugging v7.2.0 would be tackling two issues at the same time otherwise.
My understanding is that v6.5.4 is using JSC instead of the v8 engine. My assumption is that v8 is leaking memory with promises and that both versions are leaking memory when navigating between views.
@brysem 6.5.4 is the JSC runtime located here: https://github.com/NativeScript/ios-runtime
We are still debugging and looking into this issue, just more involved than expected.
Is there a resolution or a manual workaround to this issue. We are on latest Nativescript, but our app keep crashing on ios due to memory leaks.
Leaving another message to verify that this is still an issue in v8.4.0
It's 2023 and our business critical app keeps crashing on iOS because of this. Is there a way to release the memory manually? Any kind of a workaround highly appreciated. @rigor789