Open mohit92 opened 1 day ago
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.
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 [patch.unused]
in the cargo.lock file
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