Sending an immutable object to a thread

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 22 02:04:48 PDT 2015


On Tuesday, 21 July 2015 at 21:50:35 UTC, rsw0x wrote:
> On Tuesday, 21 July 2015 at 21:44:07 UTC, rsw0x wrote:
>> On Sunday, 19 July 2015 at 17:12:07 UTC, rsw0x wrote:
>>> [...]
>>
>> wow, I don't even remember posting this.
>>
>> This is (mostly) wrong, but I'm unsure if a pointer to another 
>> pointer on the stack would correctly keep its object 
>> alive(but, I believe this would just be a bug I think,) If the 
>> pointer was pointing to a pointer on the heap, then AFAICT it 
>> would keep it alive.
>
> addendum:
> http://dlang.org/garbage.html
>
>>Pointers in D can be broadly divided into two categories: Those 
>>that point to garbage collected memory, and those that do not. 
>>Examples of the latter are pointers created by calls to C's 
>>malloc(), pointers received from C library routines, pointers 
>>to static data, pointers to objects on the stack, etc.
>
>>and those that do not ... pointers to objects on the stack, etc.
>
> I believe this implies that it would *not* keep the object 
> alive.
>
> Sorry for the confusion/noise.

But as long as the original pointer is still on the stack, that 
one _will_ keep the object alive. It is only a problem if all 
pointers to a GC managed object are stored in places the GC isn't 
informed about.


More information about the Digitalmars-d-learn mailing list