Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

buffer.clear() method to explicitely free memory #2995

Closed
lfortin opened this issue Mar 23, 2012 · 8 comments
Closed

buffer.clear() method to explicitely free memory #2995

lfortin opened this issue Mar 23, 2012 · 8 comments
Labels

Comments

@lfortin
Copy link

lfortin commented Mar 23, 2012

What could be very nice:

1- provide a method to explicitly clear a buffer immediately, and all the memory it takes:

buffer.clear();

2- Make sure that memory is immediately freed when a buffer variable goes out of scope.
Example:

function test( ) {
  var buffer = new Buffer(1024 * 1024);
  buffer.fill("0");
}
test( );
// here, make sure that out-of-scope buffer doesn't take 1 Mb of memory anymore.
@TooTallNate
Copy link

Curious: What problem would this solve? When does the freeing when the garbage collector is run not work out?

@indutny
Copy link
Member

indutny commented Mar 23, 2012

Having manual memory management along with an automatic (GC) is a waste of resources and will lead to incorrect application design. Additionally, there're no real benefits of that, as it was pointed by @TooTallNate

@bnoordhuis
Copy link
Member

We're not going to do that. Buffers have been designed around the fact that they're immutable in size. Changing that will introduce all kinds of obscure bugs in both Node and third-party code for little to no benefit.

@lfortin
Copy link
Author

lfortin commented Jul 15, 2013

Thanks @trevnorris for the incoming buffer.dispose() !

trevnorris/node@36b13c7

@trevnorris
Copy link

@lfortin no promises that it'll be implemented in core. If not then I'll find a way to make this work in a module.

@ivanseidel
Copy link

404 on the trevnorris/node@36b13c7
Any other source?

@trevnorris
Copy link

@ivanseidel
Copy link

Thanks @trevnorris !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants