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:
Cats Juice
2025-06-12 12:35:14 +08:00
committed by GitHub
parent 2a9f7e1835
commit 2d17c265ca
2 changed files with 6 additions and 6 deletions

View File

@@ -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();
}
/**