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

bug(Memory Leak): Event handlers are not dropped properly #3421

Open
marc2332 opened this issue Dec 21, 2024 · 1 comment
Open

bug(Memory Leak): Event handlers are not dropped properly #3421

marc2332 opened this issue Dec 21, 2024 · 1 comment

Comments

@marc2332
Copy link
Contributor

Same issue as in #2272

I have simplified the code a bit, but both leak memory:

#![allow(non_snake_case)]
use dioxus::prelude::dioxus_core::NoOpMutations;
use dioxus::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    fn app() -> Element {
        let mut count = use_signal(|| 0);

        use_hook(|| spawn(async move {
            loop {
                tokio::time::sleep(std::time::Duration::from_nanos(1)).await;
                let val = *count.peek_unchecked();
                if val == 70 {
                    count.set(0);
                } else {
                    count.set(val + 1);
                }
            }
        }));

        rsx! {
            for el in 0..*count.read() {
                div {
                    key: "{el}",
                    div {
                        onclick: move |_| { println!("click"); },
                    }
                }
            }
        }
    }

    // create the vdom, the real_dom, and the binding layer between them
    let mut vdom = VirtualDom::new(app);

    vdom.rebuild(&mut NoOpMutations);

    // we need to run the vdom in a async runtime
    tokio::runtime::Builder::new_current_thread()
        .enable_all()
        .build()?
        .block_on(async {
            loop {
                // wait for the vdom to update
                vdom.wait_for_work().await;

                // get the mutations from the vdom
                 vdom.render_immediate(&mut NoOpMutations);
            }
        })
}

counter5.exe is same code running with Dioxus 0.5. and counter.exe is with 0.6.

image

@marc2332
Copy link
Contributor Author

If you remove the onclick event handler you will see how the usage doesn't increase the same

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

No branches or pull requests

1 participant