Skip to content

Commit d6ad5a9

Browse files
committed
fix: fix mem leaks caused by event dispatch.
1 parent 59126d7 commit d6ad5a9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

bridge/core/dart_isolate_context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class PageGroup {
3232

3333
struct DartWireContext {
3434
ScriptValue jsObject;
35+
bool is_dedicated;
36+
double context_id;
37+
multi_threading::Dispatcher* dispatcher;
3538
};
3639

3740
void InitializeBuiltInStrings(JSContext* ctx);

bridge/core/dom/events/event_target.cc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,21 @@ NativeValue EventTarget::HandleDispatchEventFromDart(int32_t argc, const NativeV
387387

388388
auto* wire = new DartWireContext();
389389
wire->jsObject = event->ToValue();
390+
wire->is_dedicated = GetExecutingContext()->isDedicated();
391+
wire->context_id = GetExecutingContext()->contextId();
392+
wire->dispatcher = GetDispatcher();
390393

391394
auto dart_object_finalize_callback = [](void* isolate_callback_data, void* peer) {
392395
auto* wire = (DartWireContext*)(peer);
393-
if (IsDartWireAlive(wire)) {
394-
DeleteDartWire(wire);
395-
}
396+
397+
wire->dispatcher->PostToJs(
398+
wire->is_dedicated, wire->context_id,
399+
[](DartWireContext* wire) -> void {
400+
if (IsDartWireAlive(wire)) {
401+
DeleteDartWire(wire);
402+
}
403+
},
404+
wire);
396405
};
397406

398407
WatchDartWire(wire);

0 commit comments

Comments
 (0)