Re: [go-nuts] Re: simplifying freeing CString

2016-10-19 Thread andrew . smith
Thanks, I actually did a test for this by calling runtime.GC() within the 
function and it is indeed collected.

On Wednesday, October 19, 2016 at 5:43:47 PM UTC+1, Ian Lance Taylor wrote:
>
> On Wed, Oct 19, 2016 at 9:04 AM,   
> wrote: 
> >> I have a follow up question.  In the above example does golang give any 
> >> guarantee about the earliest point at which the temporay WrappedString 
> >> instance is collected. I mean, is it possible that the GC will collect 
> the 
> >> WrappedString whilst the function simulatedCall is still executing (and 
> >> thereby destroying the gchar* string whilst in use) : 
> > 
> > 
> > 
> > simulatedCCall(NewWrappedString("fred").s) 
>
> Yes, for code like that it is unlikely but possible that the memory 
> allocated by NewWrappedString will be collected, and the finalizer 
> run, while executing the function.  Use runtime.KeepAlive to avoid 
> this. 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: simplifying freeing CString

2016-10-19 Thread Ian Lance Taylor
On Wed, Oct 19, 2016 at 9:04 AM,   wrote:
>> I have a follow up question.  In the above example does golang give any
>> guarantee about the earliest point at which the temporay WrappedString
>> instance is collected. I mean, is it possible that the GC will collect the
>> WrappedString whilst the function simulatedCall is still executing (and
>> thereby destroying the gchar* string whilst in use) :
>
>
>
> simulatedCCall(NewWrappedString("fred").s)

Yes, for code like that it is unlikely but possible that the memory
allocated by NewWrappedString will be collected, and the finalizer
run, while executing the function.  Use runtime.KeepAlive to avoid
this.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: simplifying freeing CString

2016-10-19 Thread andrew . smith

>
> I have a follow up question.  In the above example does golang give any 
> guarantee about the earliest point at which the temporay WrappedString 
> instance is collected. I mean, is it possible that the GC will collect the 
> WrappedString whilst the function simulatedCall is still executing (and 
> thereby destroying the gchar* string whilst in use) :
>


simulatedCCall(NewWrappedString("fred").s) 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.