-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bufferTime with bufferCreationInterval leaks memory #4084
Comments
Updated gist, please use this as the leaker: // Leak memory using Rx.bufferTime.
import * as Rx from 'rxjs';
import * as op from 'rxjs/operators';
declare var window: any;
function getHeap() {
return process.memoryUsage().heapUsed;
}
const bufSize = 4096;
const startMsecs = Date.now();
const startHeap = getHeap();
let n = 0;
function repeat(s: string, n: number): string {
let ret: string = '';
for (let i = 0; i < n; i++) ret += s;
return ret;
}
const s$ = Rx.interval(1).pipe(
op.map((i) => repeat(i.toString(), 1000)),
op.bufferTime(10, 10),
).forEach(() => {
n++;
if (n % 50 === 0) console.log(Date.now() - startMsecs, getHeap() - startHeap);
}); |
Just double confirming, am I reading correct same code snippet doesn't leak on browser but only on node.js? |
I appreciate your skepticism, but yes. I can run the same code (in Chrome) and it does not leak. Possibly related: nodejs/node#7346, which appears to regress:
|
Sounds very promising if it's related to upstream nodejs side (as you mentioned), might need few verification over different node / browser targets. |
Peeking this again, I came to feel this isn't bug actually : node, browser shows same behavior, and it's due to keep allocating resources - |
Bug Report
Current Behavior
A clear and concise description of the behavior.
When I call
bufferTime(10, 50)
orbufferTime(50, 10)
, I get memory leaks (ts-node v4.1.0, node v9.11.1). Same code (modulo Node-specific heap size determination; I used Chrome debugger) does not appear to leak on Chrome Version 68.0.3440.106 (Official Build) (64-bit).Reproduction
https://gist.github.com/arielshaqed/9114b5801d8f650b8a1ea7626b0887b4
If I omit the second
bufferTime
argument, memory does not increase.Expected behavior
Numbers should fluctuate around several hundred thousand, but remain bounded.
Actually, they increase without bound.
Environment
Possible Solution
Specifying
bufferCreationInterval
takes thebufferTime
code on a somewhat different path.Additional context/Screenshots
When I run it on my MBP:
The text was updated successfully, but these errors were encountered: