Does node::Buffer free foreign set memory on garbage collection?

40 views
Skip to first unread message

Bodo Kaiser

unread,
Apr 14, 2013, 12:59:10 PM4/14/13
to nod...@googlegroups.com
Hello,

i want to know if a buffer which I have fed with own data is able to free this or if there is an api for manual freeing.

See:
https://gist.github.com/bodokaiser/5383405

Bodo

Ben Noordhuis

unread,
Apr 14, 2013, 2:02:08 PM4/14/13
to nod...@googlegroups.com
Check src/node_buffer.h, there's a Buffer::New() method that takes a
free_callback argument.

By the way, your snippet has a bug, it's missing a return statement on
the scope.Close(...) line.

Bodo Kaiser

unread,
Apr 14, 2013, 2:08:48 PM4/14/13
to nod...@googlegroups.com
Thanks for the hint.

So the node Buffer does not free my assigned bytes when I do not use the free_callback?

Bodo
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/n1RO_L_aRPo/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Nathan Rajlich

unread,
Apr 14, 2013, 2:10:53 PM4/14/13
to nodejs
Since you're using the version of Buffer::New() where it allocates memory for you, then yes, the memory will be free'd when the Buffer is garbage collected.


You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.

Ben Noordhuis

unread,
Apr 14, 2013, 2:16:13 PM4/14/13
to nod...@googlegroups.com
On Sun, Apr 14, 2013 at 8:08 PM, Bodo Kaiser <bodo....@enabre.com> wrote:
> Thanks for the hint.
>
> So the node Buffer does not free my assigned bytes when I do not use the free_callback?
>
> Bodo

The non-free_callback versions of Buffer::New() copy the memory.
You're responsible for freeing the original memory.

Bodo Kaiser

unread,
Apr 14, 2013, 2:20:45 PM4/14/13
to nod...@googlegroups.com
Okay good to know thank you!

Bodo
Reply all
Reply to author
Forward
0 new messages