5 ms·
What relationship do you see between inheritance and GC ? Creating An instance of some object 30 levels deep in the inheritance chain does not allocate 29 extra
by wokkel 6y ago
What relationship do you see between inheritance and GC ? Creating An instance of some object 30 levels deep in the inheritance chain does not allocate 29 extra objects.
- darksaints 6y agoIt's not always that simple. For example, if you inherit from a class that has private members, you are actually going to allocate both the parent and child. https://stackoverflow.com/questions/27813539/what-happens-in-the-heap-when-class-a-inherits-class-b-in-java https://stackoverflow.com/questions/27813539/what-happens-in... Also, if you don't mark your methods and classes as final, you're gonna be allocating functions everywhere as well.
- haxen 6y ago> you are actually going to allocate both the parent and child. You're going to allocate a single memory block that contains all the state of that object, which of course includes the superclass state. But that has nothing to do with the depth of the class hiererarchy. > you're gonna be allocating functions everywhere as well. If by "function" you mean a "Java method", they are code and not data, and they are not allocated dynamically at all. In any case, this would have nothing to do with them being private or final. These options decide whether there will be an invokevirtual or invokespecial instruction to call them, where invokevirtual has more cost only before getting JIT-optimized.