News for hackers. Stuff that matters.
Re:A Garbage Collector for C and C++ by vidarh on Friday July 10, 2015 @04:21AM (#9862832)
Consider it a safeguard. One one hand it can detect (some) leaks. On the other hand if/when your app leaks it can mitigate the consequences of those leaks.

For some very specific types of apps it can also be sufficient to ditch traditional C/C++ memory management, and you can actually even gain speed doing so.

Consider e.g. code that runs a job. Most of the time you know it will need less than 32MB (or whatever) total over the (short) lifetime of the process.

So you tune the GC accordingly to not trigger any collection at all until above that level. Now most of time, a collection will never get triggered, and you're happy - all the memory is just returned to the system at the end in one swoop.

But if occasionally a job requires lots more, the GC may provide sufficient cleanup to still make it viable not to include any memory management.

My first large CGI-era webapp was in C++ and relied exactly on lots of hacks like deferring all memory de-allocation until exit to improve performance (and it worked very well - it had a considerable performance impact; other hacks included static linking to drastically cut the loading cost). We didn't use a GC; instead we had to take extra care when we knew we were going to make large allocations to do manual de-allocation in those cases if the request was potentially long-running. I'd have loved to use the Boehm GC for that.

Re:A Garbage Collector for C and C++ by pjmlp on Friday July 10, 2015 @08:40AM (#9863576)
Walter Bright uses this trick in his D compiler. Memory is not freed, just by the OS.

http://www.drdobbs.com/cpp/increasing-compiler-speed-by-over...