Description
Bug Report
Current Behavior
When instantiating a Subscription and passing a callback, that callback is saved as this._unsubscribe
of the Subscription
object:
rxjs/src/internal/Subscription.ts
Line 43 in d608cf3
When unsubscribing that Subscription, the function is called, but not nulled out afterwards:
rxjs/src/internal/Subscription.ts
Line 79 in d608cf3
This means that if it did some manual resource cleanup like closing a MessagePort, that MessagePort still can't be garbage-collected, because the callback, and therefor the Subscription, still holds a reference to it.
This is different from Subscriptions added via add()
, which are correctly de-referenced:
rxjs/src/internal/Subscription.ts
Line 66 in d608cf3
Reproduction
- REPL or Repo link:
(you can use https://stackblitz.com/ to create one to attach here)
const { port1 } = new MessageChannel()
const subscription = new Subscription(() => {
port1.close()
})
subscription.unsubscribe()
console.log(subscription._unsubscribe)
Expected behavior
After calling the callback, this._unsubscribe
should be nulled out so the callback and its references can be garbage-collected. Since a Subscription can only be unsubscribed once, there is no need to keep the reference.
Environment
- Runtime: All
- RxJS version: 6.5.5
Possible Solution
Set this._unsubscribe
to null
when unsubscribe()
is called.
Activity