Fix event handler memory leak (#2298)
* fix event handler memory leak and double drops * Prevent double dropping generational boxes * recycle instead of dropping
This commit is contained in:
1 parent
a27d4e71ed
commit
47c87568e1
7 files changed
+182
-54
No files matched your search
@@ -737,7 +737,7 @@ impl AttributeValue {
|
||||
pub fn listener<T: 'static>(mut callback: impl FnMut(Event<T>) + 'static) -> AttributeValue {
|
||||
// TODO: maybe don't use the copy-variant of EventHandler here?
|
||||
// Maybe, create an Owned variant so we are less likely to run into leaks
|
||||
AttributeValue::Listener(EventHandler::new(move |event: Event<dyn Any>| {
|
||||
AttributeValue::Listener(EventHandler::leak(move |event: Event<dyn Any>| {
|
||||
let data = event.data.downcast::<T>().unwrap();
|
||||
callback(Event {
|
||||
propagates: event.propagates,
|
||||
@@ -761,7 +761,7 @@ impl std::fmt::Debug for AttributeValue {
|
||||
Self::Float(arg0) => f.debug_tuple("Float").field(arg0).finish(),
|
||||
Self::Int(arg0) => f.debug_tuple("Int").field(arg0).finish(),
|
||||
Self::Bool(arg0) => f.debug_tuple("Bool").field(arg0).finish(),
|
||||
Self::Listener(_) => f.debug_tuple("Listener").finish(),
|
||||
Self::Listener(listener) => f.debug_tuple("Listener").field(listener).finish(),
|
||||
Self::Any(_) => f.debug_tuple("Any").finish(),
|
||||
Self::None => write!(f, "None"),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user