Skip to content

Commit 88036ab

Browse files
committed
Fix memory leaks after fixing Bug#6695
1 parent 74e04c3 commit 88036ab

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/survey-creator-core/src/components/string-editor.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export class StringEditorViewModelBase extends Base {
256256
super();
257257
this.locString = locString;
258258
this.checkMarkdownToTextConversion(this.locString.owner, this.locString.name);
259-
this.creator?.onLocaleChanded.add(this.onLocaleChanged);
259+
this.addCreatorEvents();
260260
}
261261
private onLocaleChanged = () => {
262262
this.resetPropertyValue("placeholderValue");
@@ -268,13 +268,13 @@ export class StringEditorViewModelBase extends Base {
268268
}
269269

270270
public detachFromUI() {
271+
this.removeCreatorEvents();
271272
this.connector?.onDoActivate.remove(this.activate);
272273
this.getEditorElement = undefined;
273274
this.blurEditor = undefined;
274275
}
275276

276277
public dispose(): void {
277-
this.creator?.onLocaleChanded.remove(this.onLocaleChanged);
278278
super.dispose();
279279
this.detachFromUI();
280280
}
@@ -288,12 +288,20 @@ export class StringEditorViewModelBase extends Base {
288288
}
289289
return false;
290290
}
291+
private addCreatorEvents() {
292+
this.creator?.onLocaleChanded.add(this.onLocaleChanged);
293+
}
294+
private removeCreatorEvents() {
295+
this.creator?.onLocaleChanded.remove(this.onLocaleChanged);
296+
}
291297

292298
public setLocString(locString: LocalizableString) {
299+
this.removeCreatorEvents();
293300
this.connector?.onDoActivate.remove(this.activate);
294301
this.locString = locString;
295302
this.connector = StringEditorConnector.get(locString);
296303
this.connector.onDoActivate.add(this.activate);
304+
this.addCreatorEvents();
297305
}
298306
public checkConstraints(event: any) {
299307
if (!this.compostionInProgress && this.maxLength > 0 && event.keyCode >= 32) {

0 commit comments

Comments
 (0)