mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00: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:
@@ -250,6 +250,9 @@ export class LiveData<T = unknown>
|
||||
private isPoisoned = false;
|
||||
private poisonedError: PoisonedError | null = null;
|
||||
|
||||
private _signal: Signal<T> | undefined;
|
||||
private _signalSubscription: Subscription | undefined;
|
||||
|
||||
constructor(
|
||||
initialValue: T,
|
||||
upstream:
|
||||
@@ -302,12 +305,10 @@ export class LiveData<T = unknown>
|
||||
this.next(v);
|
||||
}
|
||||
|
||||
private _signal: Signal<T> | undefined;
|
||||
|
||||
get signal(): ReadonlySignal<T> {
|
||||
if (!this._signal) {
|
||||
this._signal = signal(this.value);
|
||||
this.subscribe(v => {
|
||||
this._signalSubscription = this.subscribe(v => {
|
||||
// oxlint-disable-next-line no-non-null-assertion
|
||||
this._signal!.value = v;
|
||||
});
|
||||
@@ -464,6 +465,7 @@ export class LiveData<T = unknown>
|
||||
this.ops$.complete();
|
||||
this.raw$.complete();
|
||||
this.upstreamSubscription?.unsubscribe();
|
||||
this._signalSubscription?.unsubscribe();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user