Java – should I leave behind methods I don’t use in class?

I have a class (> 400000 instances) that is heavily used in programs with heavy performance Will leaving these methods in the class seriously affect the memory usage of each object, or is it really not important?

Solution

This class is loaded into memory the first time it is used, and is normally loaded only once In fact, the equals method of class is written as = =, which means that Java expects it to be exactly the same object

This is different from allocating memory at instantiation and deallocating class instances at garbage collection

If your class has unused fields, what is more worrying Each field consumes a small amount of memory, but it may consume a lot of memory when multiplied by the number of real-time instances This is true even if the field is initialized to null If you initialize a field as a new object, you may consume more memory, depending on the size of the object

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>