Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does immutable data "burn up" RAM in D?

Consider a worker loop that has something like:

...
auto msg = new immutable(DataWrittenMsg)(bytesWritten);
masterTid.send(msg);
...

Will this slowly but surely eat up all RAM, as time reaches Inf? Or can unused immutable data get collected by the GC?

(I'm reading TDPL Ch. 13 and I get the impression once immutable data is set it can never get unset?)

like image 767
kraybit Avatar asked Jan 25 '12 20:01

kraybit


1 Answers

No, the GC will still pick up unreferenced objects, regardless of their constness.

Regarding "once immutable data is set it can never get unset" - this is only so in the logical sense. Assuming your program's memory safety isn't compromised, all immutable heap-allocated objects your program has access to will not change for as long as they're reachable, even though the actual memory at that address can be reused once those objects become unreachable.

like image 108
Vladimir Panteleev Avatar answered Nov 03 '22 02:11

Vladimir Panteleev