How to load an instance into memory on an object or class?

If I have an O object with a giant f() method, and I load 10,000 O examples into memory. Are 10,000 f() examples loaded into memory? If so, does this mean that I would save memory if I set this function statically, if possible?

+7
source share
4 answers

Instance methods are loaded into the method scope in the JVM. it loads once, but there will be a lot of stack for each u make call to f () to keep track of the eigenvalues ​​of the variables.

+9
source

Not. There is only one instance of a loaded method.

+6
source

An instance method is just a template and is defined in the class (not in every instance). You would not save memory by making it static.

+2
source

Not. Methods are not part of the instances; they are part of the classes. It would not make sense to repeat the code for each instance (because it will never change), so the implementation is quite simple, smarter than that.

+2
source

All Articles