-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
Fix (utils): Fix memory leak in EventEmitterMixin. See #8480.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,6 +156,18 @@ const EmitterMixin = { | |
// All params provided. off() that single callback. | ||
if ( callback ) { | ||
removeCallback( emitter, event, callback ); | ||
|
||
// We must remove callbacks as well in order to prevent memory leaks. | ||
// See https://github.com/ckeditor/ckeditor5/pull/8480 | ||
const index = eventCallbacks.indexOf( callback ); | ||
|
||
if ( index !== -1 ) { | ||
if ( eventCallbacks.length === 1 ) { | ||
delete emitterInfo.callbacks[ event ]; | ||
} else { | ||
removeCallback( emitter, event, callback ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jodator
Author
Contributor
|
||
} | ||
} | ||
} | ||
// Only `emitter` and `event` provided. off() all callbacks for that event. | ||
else if ( eventCallbacks ) { | ||
|
@jodator this line is incorrect. This is doing the same thing that line 158 did. This needs to be
emitterInfo.callbacks[ event ].splice( index, 1 );
oreventCallbacks.splice( index, 1 );
The memory leak still exists when removing the non-last callback.