Skip to content

Commit

Permalink
Work for surveyjs/survey-creator#4484 - memory leaks in survey creato…
Browse files Browse the repository at this point in the history
…r - dispose computed updaters
  • Loading branch information
tsv2013 committed Aug 29, 2023
1 parent cab0b05 commit c3a45fb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export class Dependencies {
this.dependencies.forEach(dependency => {
dependency.obj.unregisterPropertyChangedHandlers([dependency.prop], dependency.id);
});
// this.currentDependency = undefined;
}
}

Expand Down Expand Up @@ -191,6 +192,7 @@ export class Base {
if (Base.currentDependencis === undefined) return;
Base.currentDependencis.addDependency(target, property);
}
public dependencies: {[key: string]: ComputedUpdater } = {};
public static get commentSuffix(): string {
return settings.commentSuffix;
}
Expand Down Expand Up @@ -307,6 +309,7 @@ export class Base {
}
this.onPropertyValueChangedCallback = undefined;
this.isDisposedValue = true;
Object.values(this.dependencies).forEach(dependencies => dependencies.dispose());
}
public get isDisposed() {
return this.isDisposedValue === true;
Expand Down
9 changes: 7 additions & 2 deletions src/jsonobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,19 @@ function getLocStringValue(
return "";
}

export function property(options?: IPropertyDecoratorOptions) {
return function (target: any, key: string) {
export function property(options: IPropertyDecoratorOptions = {}) {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
return function (target: any, key: string): void {
let processComputedUpdater = (obj: any, val: any) => {
if (!!val && typeof val === "object" && val.type === ComputedUpdater.ComputedUpdaterType) {
Base.startCollectDependencies(() => obj[key] = val.updater(), obj, key);
const result = val.updater();
const dependencies = Base.finishCollectDependencies();
val.setDependencies(dependencies);
if(obj.dependencies[key]) {
obj.dependencies[key].dispose();
}
obj.dependencies[key] = val;
return result;
}
return val;
Expand Down

0 comments on commit c3a45fb

Please sign in to comment.