toStringz note about keeping references

Jonathan M Davis jmdavisProg at gmx.com
Sun Oct 14 15:45:51 PDT 2012


On Sunday, October 14, 2012 23:38:48 Andrej Mitrovic wrote:
> toStringz takes a string (immutable(char)[]), and the GC will not
> reclaim immutable data until app exit.

If the GC never collects immutable data which has no references to it until 
the app closes, then there's a serious problem. Immutability shouldn't factor 
into that at all. Anything and everything with no references to it any longer 
should be up for collection. Any other behavior would effectively result in 
huge memory leaks - especially if you're doing a lot with strings. Maybe 
you're seeing the behavior that you're seeing because the GC mistakingly 
thinks that something points to it (as happens sometimes - especially in 32-
bit programs).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list