3 ms·
This is kind of hard to do in practice unless you’re really watching where you’re allocating memory. It’s very easy in Java to end up accidentally throwing a bu
by plandis 4y ago
This is kind of hard to do in practice unless you’re really watching where you’re allocating memory. It’s very easy in Java to end up accidentally throwing a bunch of allocated memory on the heap without realizing it.
Fwiw, the JVM now has a noop garbage collector so this is easy enough to benchmark.
- vbezhenar 4y agoCan you provide an examples of accidentally allocating memory? The only example I'm aware of is autoboxing which is huge misfeature IMO.
- kaba0 4y agoAny method call could allocate objects in their call trees, and it may not even behave consistently with new versions. But it is easy to monitor with Java’s killer observability.
- lenocinor 4y agoConcatenating lots of Strings instead of using a StringBuffer will do the trick. Sure, people who are familiar with Java know not to do that. But I’ve seen plenty of production code that concatenates.