GC: Memory keeps growing

Chris via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Apr 15 05:03:48 PDT 2015


On Wednesday, 15 April 2015 at 11:48:26 UTC, Rikki Cattermole 
wrote:
> On 15/04/2015 11:44 p.m., Chris wrote:
>> My garbage collected app starts with ~10 MB in memory, however 
>> with
>> every execution of code it grows by at least 0.2 MB (or more 
>> depending
>> on the input). Although I can see memory being freed (say it 
>> goes up to
>> 32 MB and drops to 14 MB), it keeps on growing slowly but 
>> surely.
>>
>> I use structs for the most part [1] and reuse arrays at 
>> critical points,
>> clearing them with destroy() after use. Maybe this is the 
>> problem? I
>> dunno. I'd be grateful for any hints.
>>
>> [1] The few classes I use are either singletons or 
>> instantiated only
>> once and cached when the programs starts.
>
> Sounds like you are doing a LOT of allocations. Try with -vgc 
> during compilation to find out where you are allocating.

Just did that, for the most part it's:

- indexing an associative array may cause GC allocation
- operator ~= may cause GC allocation
- operator ~ may cause GC allocation

Whereas "'new' causes GC allocation" is rare and applies only to 
classes that are instantiated only once. I use appender a lot, 
too.

There might be some low-hanging fruit there. However, before I 
change anything, maybe you guys have some suggestions.


More information about the Digitalmars-d-learn mailing list