65 points · by hepha1979 · 11y ago · 55 comments
What killed it off was generational collection. Compacting generational collectors make allocation very cheap, and they make maintenance of short-lived objects very cheap. As a result, it's reliably cheaper to allocate an object and throw it away than it is to attempt to reuse it.
So it's surprising and interesting to read that the author of this article clearly thinks that there are still benefits to object pooling. Since Alex Petrov is a very sharp guy, i have to take him at his word. But it's a shame he didn't include benchmarks to compare it to idiomatic use of a modern GC.
I'm no Java hater, but that sounds like the wrong place to use Java in the first place
Perhaps I am wrong and the technique is less familiar than I had thought?.
Woah, woah. No, object pooling is not for that case and definitely doesn't help with that. If you've re-used the object for something else and you've still got a reference to it - and you're updating it - you've got some seriously nasty bugs and randomly broken code.
Object pooling is not a 'must'. You need object pooling when you have a real time app and your total create/delete bandwidth exceeds the garbage collectors ability to process it in the 'early generation', forcing eventual 'stop the world' GC.
This was a fun thing I remember writing: https://github.com/newobj/ffwd/blob/master/Src/Core/Std/Allo... When returned to the pool, each object used the first 4 bytes of itself to point to the next free one in a list, so there was no additional overhead.
Having tens of thousands of agents constantly being garbage invalidated was the use case.
(Not really sure it's forgotten, either; it's used regularly for heavy objects, or when speed is absolutely critical.)
which is cheaper, stack object allocation/creation or object pooling, in languages like C/C++/Rust?