You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When continuously emitting events from the backend to the frontend, the memory usage grows substantially.
In my test case, after emitting 2 million events:
Frontend memory usage reaches approximately 1.1GB
Backend memory usage reaches approximately 120MB
Reproduction
1. Create a new Tauri project
pnpm create tauri-app
.../195129c6cbb-5d34 | +2 +
.../195129c6cbb-5d34 | Progress: resolved 12, reused 2, downloaded 0, added 2, done
✔ Project name · tauri-app
✔ Identifier · com.tauri-app.app
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, deno, bun)
✔ Choose your package manager · pnpm
✔ Choose your UI template · Vanilla
✔ Choose your UI flavor · TypeScript
2. Replace the source files with this
// lib.rsuse tauri::Emitter;// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/#[tauri::command]fngreet(name:&str) -> String{format!("Hello, {}! You've been greeted from Rust!", name)}#[cfg_attr(mobile, tauri::mobile_entry_point)]pubfnrun(){
tauri::Builder::default().plugin(tauri_plugin_opener::init()).invoke_handler(tauri::generate_handler![greet]).setup(|app| {let app = app.handle().clone();
tauri::async_runtime::spawn(asyncmove{
tokio::time::sleep(std::time::Duration::from_secs(5)).await;for i in0..2000000{ifletErr(err) = app.emit("test", i){eprintln!("{i}: {err}");}// sleep for a second every 10000 iterationsif i % 10000 == 0{
tokio::time::sleep(std::time::Duration::from_secs(1)).await;}}});Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");}
# Cargo.toml
[package]
name = "tauri-app"version = "0.1.0"description = "A Tauri App"authors = ["you"]
edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary# to make the lib name unique and wouldn't conflict with the bin name.# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519name = "tauri_app_lib"crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"serde = { version = "1", features = ["derive"] }
serde_json = "1"tokio = { version = "1.43.0", features = ["full"] }
// main.tsimport{invoke}from"@tauri-apps/api/core";import{listen}from"@tauri-apps/api/event";letgreetInputEl: HTMLInputElement|null;letgreetMsgEl: HTMLElement|null;asyncfunctiongreet(){if(greetMsgEl&&greetInputEl){// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/greetMsgEl.textContent=awaitinvoke("greet",{name: greetInputEl.value,});}}letcount=0;listen<number>('test',()=>{count++;if(greetMsgEl&&greetInputEl){greetMsgEl.textContent=`${count}`;}});window.addEventListener("DOMContentLoaded",()=>{greetInputEl=document.querySelector("#greet-input");greetMsgEl=document.querySelector("#greet-msg");document.querySelector("#greet-form")?.addEventListener("submit",(e)=>{e.preventDefault();greet();});});
Describe the bug
When continuously emitting events from the backend to the frontend, the memory usage grows substantially.
In my test case, after emitting 2 million events:
Reproduction
1. Create a new Tauri project
2. Replace the source files with this
3. Build and run
4. Observe the memory usage in
Task Manager
, wait for the counter to reach 2 millionExpected behavior
The memory usage should remain relatively stable regardless of the number of events emitted
Full
tauri info
outputStack trace
Additional context
This memory leak issue appears to be related to
wry
.I've created a related issue tauri-apps/wry#1489 that demonstrates similar memory leak behavior.
The text was updated successfully, but these errors were encountered: