How to find the size of the non-primitive java object?
Asked
Active
Viewed 593 times
2 Answers
1
What you're looking for is a Java Sizeof. Have a look at this article. Basically, it creates a lot of your objects and looks at the change in the available heap.

daveb
- 74,111
- 6
- 45
- 51
0
There is no predefined way in java to do that, because you rarely need to find the size anyway. In case you have some particular use case, you can find the size by writing a custom function that takes the object and finds the size based on the primitive types and references inside it. Eg. List of 10 integers = 32*10 class A with int a; Object o = 32*2 [Assuming 32 bit jvm].

amit
- 10,612
- 11
- 61
- 60