Fix memory leak in owner (#2245)

* Fix: memory leak on listeners for elements

---------

Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
Jonathan KelleyandEvan Almloff authored and GitHub committed 2024-04-04 15:32:23 -07:00
1 parent 44fe2defc2
commit 633e2a70a4
3 files changed
+16 -6

No files matched your search

+3 -5
View File
@@ -1,6 +1,5 @@
use generational_box::{GenerationalBox, UnsyncStorage};
use crate::{generational_box::current_owner, global_context::current_scope_id, Runtime, ScopeId};
use crate::{global_context::current_scope_id, Runtime, ScopeId};
use generational_box::GenerationalBox;
use std::{cell::Cell, rc::Rc};
/// A wrapper around some generic data that handles the event's state
@@ -199,8 +198,7 @@ impl<T: 'static> EventHandler<T> {
/// Create a new [`EventHandler`] from an [`FnMut`]
#[track_caller]
pub fn new(mut f: impl FnMut(T) + 'static) -> EventHandler<T> {
let owner = current_owner::<UnsyncStorage>();
let callback = owner.insert(Some(Box::new(move |event: T| {
let callback = GenerationalBox::leak(Some(Box::new(move |event: T| {
f(event);
}) as Box<dyn FnMut(T)>));
EventHandler {