Skip to content
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

Buffer.parent? #1579

Closed
tolmasky opened this issue May 1, 2015 · 2 comments
Closed

Buffer.parent? #1579

tolmasky opened this issue May 1, 2015 · 2 comments
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.

Comments

@tolmasky
Copy link
Contributor

tolmasky commented May 1, 2015

Buffers seem to have a parent object:

new Buffer('a').parent

I see no mention of this in the docs anywhere, and was just curious what this is.

Thanks,

Francisco

@silverwind silverwind added the buffer Issues and PRs related to the buffer subsystem. label May 1, 2015
@mscdex mscdex added the question Issues that look for answers. label May 1, 2015
@mscdex
Copy link
Contributor

mscdex commented May 1, 2015

buffer.parent stores the parent Buffer instance when you call buffer.slice(), since slices reference the memory of the original buffer (no data copies are made). For new Buffers not originating from a slice, it's set to a chunk of memory from the pre-existing memory pool.

Additionally, I believe it also helps with GC, so that when all slices of a particular buffer get GC'ed, the parent buffer can then be automatically and safely GC'ed.

@benjamingr
Copy link
Member

Note that undocumented properties are not something you can generally rely on in your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

5 participants