Size of Objects in Java Heap w/ Regards to Methods
Posted
by
Eric
on Stack Overflow
See other posts from Stack Overflow
or by Eric
Published on 2012-06-27T15:10:50Z
Indexed on
2012/06/27
15:15 UTC
Read the original article
Hit count: 276
I know about primitives and objects living on the heap, but how does the number of methods effect heap size of the object?
For example:
public class A {
int x;
public getX() { return x; }
}
public class B {
int x;
public getX() { return x; }
public getXString() { return String.valueOf(x); }
public doMoreInterestingStuff() { return x * 42; }
//etc
}
When instantiated, both objects live on the heap, both have memory allocated to their primitive x
, but is B allocated more heap space due to having more method signatures? Or are those ONLY on the classLoader? In this example its trivial, but when there are 100,000+ of these objects in memory at any given time I imagine it could add up.
© Stack Overflow or respective owner