-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
[bug] In Android MainActivity is leaked if a foreground service is running and makes the app unusable on next launch #11609
Comments
we're creating a global reference to the activity here so we probably need to find a way to clean it up. |
the problem with the invoke keys is wry statics which is a lifecycle issue in this case - since your app is still open in the foreground, the Rust code is still running - and the process is reused when the app is reopened. |
i'm trying some changes for the memory leak, no luck yet. |
fixes a memory leak when the activity is destroyed but the app is opened in the foreground ref tauri-apps/tauri#11609
I think i've fixed it. If you wanna early try it, add the following to the Cargo.toml file: [patch.crates-io]
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "dev" }
tauri-plugin = { git = "https://github.com/tauri-apps/tauri", branch = "dev" }
tauri-build = { git = "https://github.com/tauri-apps/tauri", branch = "dev" }
tao = { git = "https://github.com/tauri-apps/tao", branch = "fix/android-leak" }
wry = { git = "https://github.com/lucasfernog/wry", branch = "fix/android" } (to validate if the patches are properly applied, you can see if there's no |
fixes a memory leak when the activity is destroyed but the app is opened in the foreground ref tauri-apps/tauri#11609
@lucasfernog fyi ever since tauri-apps/wry#1414 there have been reports of android apps crashing due to Borrow errors. Please look into tauri-apps/wry#1420 |
Describe the bug
It seems that Tauri Android app don't expect the application process to outlive the MainActivity, which is common in android world if you are running a foreground service
In this case when you relaunch the app, Tauri has two instances of MainActivity and RustWebview which causes TAURI_INVOKE_KEY mismatch causing the app to become unsuable.
Reproduction
Download and build the sample project. Please build it in release mode, as the repro steps require killing the app. Be sure to add your release key and configure local.properties to set up signing keys. Link to the repo: https://github.com/m-byondlabs/screenshare-mobile-tauri
Launch the app, click the "Start Share" button, and allow the prompt to start screen sharing.
You should see a screencast icon indicating that the foreground service is actively capturing the screen recording.
Swipe up to close the MainActivity; you’ll notice that the foreground service continues capturing the screen (this is intended and expected behavior).
Reopen the app and click "Start Share" or "Stop Share." You will observe a log indicating a TAURI_INVOKE_KEY mismatch.
If you generate a heap dump, you’ll find two instances of MainActivity, meaning the previous activity is leaked and remains in memory.
I've verified that my code does not retain any references to the activity, so it appears that the Tauri Plugin manager or another code path in Tauri may be holding onto that instance.
Expected behavior
Once the activity is destroyed, it should not stay in the memory
Full
tauri info
outputStack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: