Description
Edit: Below I describe a bug that I assumed was an issue with the emulator. That might be the case, but alternatively could there be a navigation bug?
In my case, the emulator had been open a long time, and the pages where the issue appeared had experienced a lot of back and forth navigation. Is it possible that the navigation "fills up" (maybe the cache gets full), and this can lead to strange navigation behavior?
In my case, after many many (over a hundred) back and forths on the page, the navigation button just stopped working and the page would automatically navigate back to an earlier page (without any navigation being ordered). Maybe this was because of an over-used navigation?
If not, then it is probably an emulator bug as described below:
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
- CLI: 5.1.1
- Cross-platform modules: 5.1.1
- Android Runtime: 5.1.0
- iOS Runtime: 5.1.1
Describe the bug
I was running the emulator (ios, iPad) for approximately a day and half (ie, starting the emulator and not stopping it for a day and half; the computer was periodically asleep during the time, but the emulator was not shut down.). At that point, it started having faulty router navigation.
Specifically, (i) a navigation button would stop working and (ii) the emulator would navigate away from a certain page immediately upon going back to that page (even though navigation had not been ordered).
Navigation on the app is done with Router, Navigation Extras, and Active Router.
It is very unlikely this is a code error, because I have run the same code multiple times on different emulators (and on my device), without seeing this behavior.
I closed the emulator. On running it again, the behavior has stopped (and navigation is working properly).
So it seems likely to me that the navigation "glitch" was specific to the emulator, and probably a result of the emulator running for so long.
A breakdown in the emulator after running it for so long is not a significant concern. However, it would be helpful to know whether others have seen buggy behavior in an emulator open for a long time, as it would help me confirm whether or not there is some hidden code problem, a bug in router with Nativescript, or an issue with the iOS back button.
To Reproduce
I was running the emulator (using a webpack bundle), focusing on ipad. So I ran:
$ tns run ios --device "iPad Pro (12.9-inch) (2nd generation)" --bundle --env.development --env.uglify --env.aot
The emulator ran for about a day and a half (ie, 36 hrs+) before the behavior began. The computer was asleep periodically during the time, but the emulator was not closed.
Activity
KristianDD commentedon Feb 8, 2019
Hi @NL33 ,
We haven't observed such behavior while developing with the framework on a simulator. The simulator is just a common process running in the operating system and its state is not guaranteed to be properly preserved during sleep/wake cycles.
We recommend that you stop the previous
tns runsession and start a fresh one.We are also not aware of any issues with multiple back and forth navigation and also have an automated test that verifies this functionality. Did you experience this issue on a fresh simulator instance within a single
tns runsession, without wake/awake of the computer? If so there might be a memory leak caused by the code of your application. You can verify that by trying to reproduce the issue with a blank angular project with drawer/tab navigation.NL33 commentedon Feb 8, 2019
Thank you, @KristianDD. When I stopped the session and started a new one, the problem went away. My "best" guess is that maybe there is some memory leakage, but just a little, and it takes a long time to build up, so you would only experience it after a long time?
In case that is the issue, I have put clearHistory="true" on the key navigations that were causing issues. I am thinking this is the key way to combat memory leaks. Does that sound right?
NL33 commentedon Feb 8, 2019
As a bit more info, it does seem that memory use on the app is steadily increasing as the app is used (at least on the emulator). With each navigation, memory use grows. So perhaps that was the issue. I had hoped that putting clearHistory="true" would reset the memory to avoid this problem. But xcode shows memory use increasing with each navigation even with clearHistory.
Is there something else I need to be doing? I have researched possible causes of memory leaks and cannot see what might be happening here, other than if NS 5.1+webpack for iOS has small memory leaks all the time. It would be great if there is something I can run periodically in the app to lower memory usage.
I have tried garbage collection, but that did not seem to make the difference. If the app was at, say, 285 mbs before running GC, it stayed there after, and would slowly increase with further navigation.
Is there anything I can do to reset the memory in the app while it is running?
NickIliev commentedon Feb 12, 2019
Moving this issue to the modules repository as it seems related more to a memory leak than to a CLI issue.
@NL33 if possible please provide us with a sample demo app which we could use to investigate the case. It seems that you are using an Angular based app but are you having issues on specific pages or on each navigation? Are you using page transitions and is the issue only happening on iOS or on Android? Posting a simple demo that reproduces the issue will greatly help in understanding the cause.
NickIliev commentedon Feb 12, 2019
This issue was moved to NativeScript/NativeScript#6890