Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): stops leaking memory on system keyboard rotation #6552

Merged
merged 1 commit into from
May 23, 2022

Conversation

sgschantz
Copy link
Contributor

@sgschantz sgschantz commented Apr 21, 2022

fixes #6547

Rotation of the Keyman system in iOS was causing the app to leak memory as the old web view instances used to implement the system keyboard were not being deallocated. This would cause the Keyman keyboard extension to consume more memory and potentially become unstable.

Before this fix, memory consumption increases with each rotation and is not released:

image

After this fix, memory is quickly reclaimed after many rotations as shown in Xcode:

image

@sgschantz sgschantz requested a review from jahorton April 21, 2022 09:49
@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Apr 21, 2022
@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Apr 21, 2022

User Test Results

Test specification and instructions

  • TEST_SAFARI_DEVELOPER (PASSED): Keyman instances no longer increase in Safari developer with each rotation

Test Artifacts

@jahorton
Copy link
Contributor

I presume that the keyboard still has to reload after rotation for your testing setup, right? Just... no memory leak now?

@sgschantz sgschantz marked this pull request as ready for review April 25, 2022 08:12
@sgschantz
Copy link
Contributor Author

Yes, the keyboard is still reloaded whenever I rotate, but is now able to clean up the old keyboard view after the rotation.

Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcdurdin
Copy link
Member

Note: still need to complete user testing before merge.

@sgschantz
Copy link
Contributor Author

@mcdurdin How do we define user tests to determine whether memory is leaking or not? I could only do so with development tools.

@mcdurdin
Copy link
Member

Re user tests, I'm looking more at regression tests -- making sure there are no unexpected functionality breakages -- in PRs like this one.

@jahorton
Copy link
Contributor

Investigation of #6191 has determined another circumstance that may cause the same behavior that leads to memory leaks. I'd strongly advise checking these changes against the experiments documented in this comment: #6191 (comment).

Additionally, there's an interesting WebView callback documented there that may be worth some consideration.


A question: does this anti-leak fix prevent replication of the WebView in Safari's Develop menu? That is...

Screen Shot 2022-05-20 at 8 37 20 AM

->

Screen Shot 2022-05-20 at 8 37 43 AM

If it does prevent the old instance from being preserved, that sounds like a potential basis for user tests. They'd be a bit technical, and would require setup (b/c Safari's Develop menu), but it'd at least be a viable approach.

@mcdurdin
Copy link
Member

They'd be a bit technical, and would require setup (b/c Safari's Develop menu), but it'd at least be a viable approach.

There's no reason why we can't get a dev to run a test -- there's no rule saying only testers can run tests.

So I think in this case, one of the dev team should test the built artifact (that is, @sgschantz or @jahorton most likely). I think it'll be a quick and straightforward test for you.

That's aside from the regression test which is still important for the test team to run.

@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR has-user-test labels May 20, 2022
@keymanapp-test-bot keymanapp-test-bot bot added user-test-missing User tests have not yet been defined for the PR and removed user-test-required User tests have not been completed labels May 20, 2022
@sgschantz
Copy link
Contributor Author

sgschantz commented May 20, 2022

User Testing

  • TEST_SAFARI_DEVELOPER: Debug Keyman on a Mac with Safari and rotate the device with the system keyboard open in the iOS Safari browser. Verify that multiple instances of Keyman do not appear in the Develop menu on the Mac.

@keymanapp-test-bot keymanapp-test-bot bot added has-user-test user-test-required User tests have not been completed and removed user-test-missing User tests have not yet been defined for the PR labels May 20, 2022
@sgschantz
Copy link
Contributor Author

I tested to see whether Keyman instances continue to be added to the Safari Developer menu, and they are being cleaned up. However, two appear when SWKeyboard is first attached. After rotating, it jumps to three, but it drops back down to two again within seconds. This happens for each rotation.

Not sure why I would have two entries for Keyman instead of one. That could still be a problem, but the leak appears to be gone.

My User Test Results are not appearing as I would expect them to...did I fail to specify them correctly?

@mcdurdin
Copy link
Member

I tested to see whether Keyman instances continue to be added to the Safari Developer menu, and they are being cleaned up. However, two appear when SWKeyboard is first attached. After rotating, it jumps to three, but it drops back down to two again within seconds. This happens for each rotation.

Not sure why I would have two entries for Keyman instead of one. That could still be a problem, but the leak appears to be gone.

Is one the in-app and the other the system keyboard perhaps?

My User Test Results are not appearing as I would expect them to...did I fail to specify them correctly?

Looks like you specified correctly. This was due to an issue on keymanapp/status.keyman.com#253, now resolved.

@sgschantz
Copy link
Contributor Author

  • TEST_SAFARI_DEVELOPER (PASSED): Keyman instances no longer increase in Safari developer with each rotation

@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-required User tests have not been completed label May 23, 2022
@sgschantz sgschantz merged commit 030f31d into beta May 23, 2022
@sgschantz sgschantz deleted the fix/ios/6547-rotation-memory-leak branch May 23, 2022 02:11
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 15.0.251-beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

bug(ios): memory leak when rotating device
5 participants