Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the memory is allocated for class member functions in Java

I found a similar question to mine:

"Is class member function code memory allocated once or at every instantiation of objects? ", which can be found here

But the answer there only talked about the case for C/C++. Could anyone please tell me the answer to this question if I am using Java?

like image 956
RecSys_2010 Avatar asked Nov 23 '25 14:11

RecSys_2010


1 Answers

Is class member function code memory allocated once or at every instantiation of objects

It is allocated once per class, not once per object. To be precise, it is allocated once per class/classloader pair. You can think of it as being allocated by the compiler, as long as you understand the compiler to include whatever the JIT or HotSpot does.

like image 124
user207421 Avatar answered Nov 25 '25 02:11

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!