Classes on stack

Johan j at j.nl
Thu Sep 1 20:11:34 UTC 2022


On Thursday, 1 September 2022 at 13:23:42 UTC, Steven 
Schveighoffer wrote:
> On 9/1/22 6:13 AM, Redwan wrote:
>> 
>> OK tnx. another problem that probably is related to this issue.
>> I compiled this worthless code:
>> ```
>> void main() {}
>> ```
>> 
>> also this one:
>> ```
>> @nogc void main() {}
>> ```
>> 
>> 
>> the valgrind result:
>> ```
>> ...
>> total heap usage: 143 alloc, 141 frees, 13,236 bytes allocated
>> ...
>> ```
>> 
>> !!!
>> what's this means??
>> from where comes this allocations and also leaks???
>
> The runtime does some allocations before running main. But 
> these are all C malloc allocations and not GC allocations. 
> There should be zero GC usage in these programs.

Hi Steven,
   I think you would agree that one hundred and forty three 
allocations (=malloc calls?) is a very large (unacceptable) 
amount for just starting and shutting down the runtime of D.

> As for "leaks", I think it would tell you that. Looking on the 
> internet, this may count for "reachable" data, that is, data 
> that is allocated, and still referenced at program exit. Such 
> memory is not a "leak" in the sense that you just stopped 
> pointing at it and never freed it.

Matching deallocations should also be required of a language 
runtime. Every user is forced to use the druntime, it is not an 
optional component (yes -betterC, come on). One example mentioned 
on StackOverflow is the case of a DLL [1].

regards,
   Johan

[1] 
https://stackoverflow.com/questions/3840582/still-reachable-leak-detected-by-valgrind#comment90930092_3857638


More information about the Digitalmars-d mailing list