ReactiveX / rxjs

A reactive programming library for JavaScript
https://rxjs.dev
Apache License 2.0
30.7k stars 3k forks source link

GroupBy GroupDurationSubscriber references retained - memory build up #2661

Closed crunchie84 closed 7 years ago

crunchie84 commented 7 years ago

RxJS version: 5.4.0

Code to reproduce:

const Rx = require('rxjs/Rx');

Rx.Observable.interval(500)
  .groupBy(
    i => i,
    null,
    i => i.take(1)
  )
  .subscribe(
    null,
    err => console.log('err: ' + err),
    () => console.log('completed')
  );
  1. Invoke code using node --debug-brk --inspect index.js
  2. attach the chrome debugger
  3. take heap snapshot before letting code run
  4. after ~30 seconds take another heap snapshot
  5. => 60 GroupDurationSubscriber's still around in memory

Expected behaviour:

GroupDurationSubscribers should be removed from the (GroupBy) parent subscription once completed.

Actual behaviour:

GroupDurationSubscribers are retained in memory.

screen shot 2017-06-13 at 14 31 57

Additional information:

When the GroupDurationSubscriber is completed it invokes this.parent.removeGroup which removes the group but it never invokes this.parent.remove(this) to let the parent (groupBy operator) remove the reference to the GroupDurationSubscriber so it can be garbage collected.

This behaviour was implemented in rxjs4

Only when the GroupBy operator completes are all the subscriptions let go off and garbage collected.

lock[bot] commented 6 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.