ARC on Objects not Class Definitions

NX via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 7 05:38:14 PST 2015


On Thursday, 5 November 2015 at 01:42:18 UTC, Adam D. Ruppe wrote:
> The object itself needs to know it because the object may pass 
> out references to itself.
>
> Consider something like this:
>
> class MyString {
>    private char[128] data_;
>    private int length_;
>
>    char[] getData() { return this.data_[0 .. length_]; }
> }
>
> How you allocate that isn't terribly important. You might 
> malloc it, you might gc it, you might stick it on the stack. 
> (This is all possible, even easy, with D today btw.)
>
> But, when should it be freed?
>
> char[] getString() {
>    MyString s = make!myString;
>    return s.getData();
>    // does s get freed here? what about the returned member 
> though?
> }

How can class coder possibly know what's happening outside of his 
implementation or how can compiler understand a reference to a 
class member is being returned ? Doesn't this require full 
control flow analysis ?

Enlighten me please...


More information about the Digitalmars-d mailing list