I need a detailed document about druntime.
Ferhat Kurtulmuş
aferust at gmail.com
Mon Oct 11 15:27:54 UTC 2021
On Monday, 11 October 2021 at 15:24:07 UTC, Adam D Ruppe wrote:
> On Monday, 11 October 2021 at 15:18:11 UTC, Ferhat Kurtulmuş
> wrote:
>> "Each call to initialize must be paired by a call to
>> terminate.'
>
> It is so the refcount works out.
>
> When you call initialize, it does something like:
>
> if(refcount == 0)
> actually intialize; // calls constructors etc
> refcount++;
>
>
> When you call terminate, it does:
>
> refcount--;
> if(refcount == 0)
> actually terminate; // calls destructors etc
>
>
>
> If you don't pair it, the refcount will be off, so the next
> call to terminate will still see ref > 0 and not actually
> terminate.
>
> The D main inserts a call to init before main and a call to
> terminate after main automatically.
That makes sense, now I see, thank you again Adam.
More information about the Digitalmars-d-learn
mailing list