Skip to content

Instantly share code, notes, and snippets.

@arielshaqed
Last active September 3, 2018 12:09
Show Gist options
  • Save arielshaqed/9114b5801d8f650b8a1ea7626b0887b4 to your computer and use it in GitHub Desktop.
Save arielshaqed/9114b5801d8f650b8a1ea7626b0887b4 to your computer and use it in GitHub Desktop.
// 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment