-
Notifications
You must be signed in to change notification settings - Fork 7.3k
buffer: toArrayBuffer() memory leak #7609
Comments
I'm not sure there's much we can do, it's a tight loop allocating a crap load of memory, give the gc some time to run. |
@tjfontaine rewrite here: var ITER = 1e3;
var b = new Buffer(1024 * 1024);
if (!global.gc)
throw new Error('Run with --expose-gc');
for (var i = 0; i < ITER; i++) {
b.toArrayBuffer();
gc();
} Running:
Evidence right now is that there's a leak. Going to take a closer look. |
Issue is that |
I've posted a question on the v8-users mailing list. As of right now I don't see how doing this is possible, and this presents a fairly significant memory leak. For the moment I think it smart to remove /cc @tjfontaine |
Unfortunately the quickest/safest fix was to remove This is still an API we'd be fine to support, but need to work with the v8 team before it can happen reliably. For that reason, going to leave this issue open. |
Maybe some wrapper will help? |
@trevnorris here is quite simple solution: Buffer.prototype.toArrayBuffer = function() {
var arrayBuffer = new ArrayBuffer(this.length);
var array = new Uint8Array(arrayBuffer);
smalloc.copyOnto(this, 0, array, 0, this.length);
return arrayBuffer;
}; |
@vkurchatkin WTF... That's a really strange side effect of V8's implementation details. It shouldn't work to use Thanks for the find. We'll have to confirm w/ the V8 team there aren't any strange unforeseen issues before using this solution. UPDATE: Waiting for a response from the following: https://groups.google.com/d/msg/v8-dev/qathcB2-M-A/MVKwE8oHVH4J |
@trevnorris ... any updates on this one? |
@jasnell Never got a response. Starting in 4.3 Buffers are backed by Uint8Array anyway so it's a non-issue down the pipe. I don't think it's worth the time to reimplement this feature before then. Anway, technically this was fixed when the commit was reverted. |
Simple test script:
This would cause my machine to swap to death if I hadn't set application memory consumption limits.
The text was updated successfully, but these errors were encountered: