Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the memory footprint of a method intensive Java object?

Suppose I have a Java class that has 100K worth of method code containing NO variables, but only 20 bytes of attributes.

I instantiate 1000 objects from this class.

Have I consumed 100,000K of memory? Or only 100K + (20bytes * 1000)? Or something else altogether?

like image 272
mmc Avatar asked Dec 01 '09 15:12

mmc


1 Answers

The memory footprint for loading the class itself will approximately correspond to the code size, but the code will not be duplicated for each instance of the class. An instance will only require as much memory as the instance attributes + some overhead for managing the object instance itself.

like image 116
jarnbjo Avatar answered Nov 14 '22 22:11

jarnbjo