107 points · by EvilTrout · 17y ago · 35 comments
We're keepin' it real
All programmers cause memory management issues, even the folks who write garbage collectors. Those folks have typically forgotten more about memory management than you or I will ever know. If you do not have a compelling reason to believe that you will be better than them quite literally all of the time, then you might want to learn to love the GC.
(See also: trying to out-optimize both gcc and the processor pipelining which you don't really understand anyhow, reimplementing core features of your web stack to "do them right this time", etc etc.)
With garbage collection it's possible to have perfectly correct code which nonetheless breaks horribly as a result of the garbage collector being "smart" in very stupid ways.
Bah. Your original comment was that GC became too slow, not that it didn't work correctly. Using malloc/free, you're dependent upon the system allocator, and so you have no time or space overhead guarantees from the allocator. Chaining free coalesce, OS paging, etc. can easily make you miss a soft-realtime deadline, make your UI pause, etc.
Obviously manual memory management is very dangerous and straight up not for the average programmer.
But if you look thorough GC code by great hackers. You'll notice a style that looks almost like free/malloc in that they take deliberate care to make life easy for the GC.
And on the other hand, programmers who are completely oblivious to how memory works, often write code which can confuse even the best GC so much that you essentially end up with a big memory leak. Strictly speaking the memory isn't leaking, the GC just can't quite dare clean it up.
The lesson is, even the best VM and GC won't make bad programmers into good ones.
Dunno about you, but if I accidentally use 800 kB of stack, I want the computer to emit fire every time the function is called.
(1-2x) * 14 = 1- x => x = 13/27
which means now ruby spends 13/27 time on GC, fast enough? (before patch, it spends 26/27 time on GC, really bad)