bug(ios): keyboard terminated by iOS due to use of too much memory
- Dominant language
- Pascal
- Stars
- 534
- Forks
- 143
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 113
Description
### Describe the bug
We have a host of Sentry events with the following title: "WatchdogTermination: The OS watchdog terminated your app, possibly because it overused RAM."
This is the way iOS enforces its memory-constraint rules on our system keyboard, which acts as a custom extension within iOS. According to React documentation, "48 MB or less." Other sources suggest "30 MB or less".
As noted by https://stackoverflow.com/a/45658368, there is a way to check for signals about running too close to the limit... but we don't always see those signals in the Sentry event reports.
----
Also, there's something... else I'm seeing in these reports that is a bit concerning. It also occurs in some of the "App hanging for at least 2000 ms." reports to do with iOS launch time constraints.
[Here's one good candidate report.](https://keyman.sentry.io/issues/4190312022/events/ba996d872a3b4693a4801d834feb2e95/) Go to the Breadcrumbs section, then click "View All" near its bottom. **Do the same with any further linked reports in this description.**
Of note for this report: "Loaded keyboard." appears _**4 separate times**_ in the breadcrumb logs. Timestamps:
- 04:32:51.585
- 04:32:51.967
- _Very quick succession there._
- 04:33:03.853 (approximately 14 seconds after the previous one)
- 04:33:29.596 (another 26 seconds later)
[Another report, this one having received a low-memory signal](https://keyman.sentry.io/issues/4190312022/events/9cf7e60781fd4184bc52cc08913b8789/?project=5983521)
[This one has logs over a wider range of time, but similar pattern](https://keyman.sentry.io/issues/4190312022/events/ac3d5655592741d495f88ea11a26c1f0/?project=5983521)
I can't help but think about how we occasionally see new "instances" of the keyboard appear in the debug menu of desktop Safari when connected to a device + app for debugging the keyboard - where an old instance... technically still exists, but is no longer connected. Is the same underlying behavior happening on these devices?
... in which case, a question: should this happen, why are the old instances still "alive" in a sense? The natural assumption - there's something that prevents them from being garbage-collected. Since they can't be GC'd, we get a memory leak - and once grown too far, that would certainly be a reasonable cause to kill the app-extension.
_If_ true, my next thought - we make use of the "Notification center" or similar for within-app notifications. Granted, the app notifications themselves shouldn't exist within the keyboard... but if there _is_ some kind of notification that is listened for, in either direction - from the keyboard to `Manager` or vice-versa - something like that, if not disconnected, could easily be the site of lingering strong-references preserving the old instances.
### Reproduce the bug
_No response_
### Expected behavior
_No response_
### Related issues
_No response_
### Keyman apps
- [ ] Keyman for Android
- [X] Keyman for iPhone and iPad
- [ ] Keyman for Linux
- [ ] Keyman for macOS
- [ ] Keyman for Windows
- [ ] Keyman Developer
- [ ] KeymanWeb
- [ ] Other - give details at bottom of form
### Keyman version
_No response_
### Operating system
_No response_
### Device
_No response_
### Target application
_No response_
### Browser
_No response_
### Keyboard name
_No response_
### Keyboard version
_No response_
### Language name
_No response_
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.