# Rb\_str\_new2

**URL:** https://rubytalk.org/t/rb-str-new2/10957
**Category:** ruby-talk
**Created:** [10 April 2004 16:19 UTC](https://rubytalk.org/t/rb-str-new2/10957 "2004-04-10T16:19:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Hadmut\_Danisch](https://avatars.discourse-cdn.com/v4/letter/h/e99b99/32.png) [@Hadmut\_Danisch](https://rubytalk.org/u/Hadmut_Danisch)
#### Post date: [10 April 2004 16:19 UTC](https://rubytalk.org/t/rb-str-new2/10957/1 "2004-04-10T16:19:15Z")

</div>

Hi,

if I use rb\_str\_new2(something) to return a string value from within  
a C function, do I have to free something after that or is something  
used within the resulting ruby object?

regards  
Hadmut

---

<div class="post-metadata">

### Author: ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)
#### Post date: [10 April 2004 16:26 UTC](https://rubytalk.org/t/rb-str-new2/10957/2 "2004-04-10T16:26:18Z")

</div>

> if I use rb\_str\_new2(something) to return a string value from within  
> a C function, do I have to free something after that or is something  
> used within the resulting ruby object?

rb\_str\_new2(something) duplicate `something' otherwise it will not  
possible to write

&nbsp;&nbsp;&nbsp;VALUE tt(VALUE obj)  
&nbsp;&nbsp;&nbsp;{  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return rb\_str\_new2("aa");  
&nbsp;&nbsp;&nbsp;}

Guy Decoux

---

<div class="post-metadata">

### Author: ![Tim\_Hunter](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@Tim\_Hunter](https://rubytalk.org/u/Tim_Hunter)
#### Post date: [10 April 2004 16:29 UTC](https://rubytalk.org/t/rb-str-new2/10957/3 "2004-04-10T16:29:15Z")

</div>

GC will clean it up for you after you’re finished with it (that is, when  
nothing refers to it any longer).

> **···**
>
> On Sat, 10 Apr 2004 18:16:04 +0200, Hadmut Danisch wrote:
> 
> > Hi,
> > 
> > if I use rb\_str\_new2(something) to return a string value from within a C  
> > function, do I have to free something after that or is something used  
> > within the resulting ruby object?
> > 
> > regards  
> > Hadmut
