Erik Engheim
2 min readJun 13, 2021

--

Why do you assume a battle? That seems like a rather toxic attitude? If I am wrong, I am wrong. I regularly update my articles based on feedback pointing our mistakes I have made.

Stating that everything I write is wrong while not articulating why is a low-blow, and not something I think anyone can take serious. I implore anyone who thinks that is the case to simply research 3-4 of my statements themselves. I think most readers will conclude that your claims are totally unreasonable.

You may not agree with my conclusion but that is different from claiming everything used to support that conclusion is wrong.

I am an old C/C++ progammer so you don't need to attempt to lecture me on how stack and heap allocation decisions even matter in non-GC languages. However that is completely beside the point. The point is that value types makes it easier to perform stack allocations, and by allowing more stack allocations you can cut down on the required heap allocations.

This even applies to languages which don't use GC such as Objective-C. Now, I know people will claim Automatic Reference Counting (ARC) is a GC strategy, but older versions of Objective-C did not have ARC. You had to manually increment and decrement the reference count yourself.

The object system of Objective-C did not have value types. Instead you relied on the fact that it was a superset of C, so you could use C structs. However this mean that you could not make stack allocated objects in Objective-C easily the way you can in Go, with full object behavior, such as having polymorphism, methods etc. Thus if you used the object-oriented part of Objective-C you could end up with a lot more heap allocations than say its competitor C++, which better supported stack allocation of objects.

As for escape analysis. I don't have any problems updating my story if I am incorrect here. But the current Java SE 16 documentation says the following:

It does not replace a heap allocation with a stack allocation for objects that do not globally escape.

https://docs.oracle.com/en/java/javase/16/vm/java-hotspot-virtual-machine-performance-enhancements.html#GUID-6BD8FCB5-995B-4AE9-BFAA-B2C7DE2BA5CD

While not entirely clear to me, it seems to be the consensus among people discussing this online, that this means that escape analysis is not used in Java to stack allocate objects.

If this is wrong, then I think both my readers and me would be happy to hear your explanation, and perhaps some link clarifying this issue.

--

--

Erik Engheim
Erik Engheim

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Responses (1)