My question is related to memory footprint in java for class without data member. Suppose in java I have a class which doesn't have data member and it only contains methods. So if I am creating instance of particular class then does it occupies memory in primary memory except object reference memory ?
Ultimately, every Java object know its class and has a synchronization primitive optionally attached to it (though this
can be synthetic). That's two references which it is difficult to make a java.lang.Object
instance do without. Everything else derives from that class, so you've got a floor for costs which worked out to be at least 8 bytes in Java 1.3.1. A profiler will tell you current costs if you really need them.
Yes, it does, because at minimum even an "empty" object has a pointer to its type information.
Let's be clear. References TO your object will, of course, take space. But your object will also take space for its 'this' pointer (i.e. so you can distinguish different instances) and also for the fields of any superclasses - e.g. Object - and finally whatever overhead the heap's internal datastructures have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With