mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 06:16:59 +08:00
fix: memory leak due to missing unsubscribe (#12777)
- unsubscribe `Signal` not correctly - missing un-subscription for `Livedata.signal` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved resource management to ensure subscriptions are properly cleaned up, reducing potential memory leaks and improving overall app stability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -541,9 +541,7 @@ export class AffineToolbarWidget extends WidgetComponent {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => {
|
disposables.add(subscription);
|
||||||
subscription.unsubscribe();
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -250,6 +250,9 @@ export class LiveData<T = unknown>
|
|||||||
private isPoisoned = false;
|
private isPoisoned = false;
|
||||||
private poisonedError: PoisonedError | null = null;
|
private poisonedError: PoisonedError | null = null;
|
||||||
|
|
||||||
|
private _signal: Signal<T> | undefined;
|
||||||
|
private _signalSubscription: Subscription | undefined;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
initialValue: T,
|
initialValue: T,
|
||||||
upstream:
|
upstream:
|
||||||
@@ -302,12 +305,10 @@ export class LiveData<T = unknown>
|
|||||||
this.next(v);
|
this.next(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _signal: Signal<T> | undefined;
|
|
||||||
|
|
||||||
get signal(): ReadonlySignal<T> {
|
get signal(): ReadonlySignal<T> {
|
||||||
if (!this._signal) {
|
if (!this._signal) {
|
||||||
this._signal = signal(this.value);
|
this._signal = signal(this.value);
|
||||||
this.subscribe(v => {
|
this._signalSubscription = this.subscribe(v => {
|
||||||
// oxlint-disable-next-line no-non-null-assertion
|
// oxlint-disable-next-line no-non-null-assertion
|
||||||
this._signal!.value = v;
|
this._signal!.value = v;
|
||||||
});
|
});
|
||||||
@@ -464,6 +465,7 @@ export class LiveData<T = unknown>
|
|||||||
this.ops$.complete();
|
this.ops$.complete();
|
||||||
this.raw$.complete();
|
this.raw$.complete();
|
||||||
this.upstreamSubscription?.unsubscribe();
|
this.upstreamSubscription?.unsubscribe();
|
||||||
|
this._signalSubscription?.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user