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: Potential memory leak (maybe just on native-core) #1361

Closed
marc2332 opened this issue Aug 15, 2023 · 1 comment · Fixed by #1363 or #1364
Closed

bug: Potential memory leak (maybe just on native-core) #1361

marc2332 opened this issue Aug 15, 2023 · 1 comment · Fixed by #1363 or #1364
Labels
bug Something isn't working native-core Related to the native-core crate

Comments

@marc2332
Copy link
Contributor

Problem

Removing X elements and adding them back should maintain the same memory usage, instead it always increases

Steps To Reproduce

Run this modified example: https://github.com/marc2332/dioxus/blob/memory-leak/packages/native-core/examples/memory-leak.rs

Expected behavior

Memory should not increase if the DOM size is the same.

Screenshots

NVIDIA_Share_zAt6ThMzOj.mp4

Environment:

  • Dioxus version: master
  • Rust version: 1.71
  • OS info: Windows
  • App platform: No renderer
@ealmloff ealmloff added bug Something isn't working native-core Related to the native-core crate labels Aug 15, 2023
@ealmloff
Copy link
Member

ealmloff commented Aug 15, 2023

This code leaks memory with just core:

#![allow(non_snake_case)]
use dioxus::prelude::*;
use std::sync::atomic::AtomicUsize;

fn main() {
    fn app(cx: Scope) -> Element {
        Some({
            let __cx = cx;
            static TEMPLATE: ::dioxus::core::Template = ::dioxus::core::Template {
                name: "examples/readme.rs:14:9:432",
                roots: &[::dioxus::core::TemplateNode::Dynamic { id: 0usize }],
                node_paths: &[&[0u8]],
                attr_paths: &[],
            };
            ::dioxus::core::VNode {
                parent: None,
                key: None,
                template: std::cell::Cell::new(TEMPLATE),
                root_ids: Default::default(),
                dynamic_nodes: __cx.bump().alloc([__cx.make_node("Testing")]),
                dynamic_attrs: __cx.bump().alloc([]),
            }
        })
    }

    let mut vdom = VirtualDom::new(app);

    let _ = vdom.rebuild();

    loop {
        // get the mutations from the vdom
        {
            let mutations = vdom.render_immediate();
            println!("Mutations: {:#?}", mutations);
        }
        vdom.mark_dirty(ScopeId(0));
        println!("{vdom:#?}");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working native-core Related to the native-core crate
Projects
None yet
2 participants