Performance is an important and interesting area in Java programming language. However, at least few of these might be JVM specific, and hence use them with care and good understanding. [node:read-more:link]
This note will provide a quick overview of different out of memory errors you might enounter, how to identify the type of the error, how you can analyze them further and how you can try to avoid them in future. We will also see some JVM flags which can help us in this analysis.
We will see the four main cases of out of memory error:
Every class in Java has a finalize() method inherited from the Object class, which will be called by GC when the object is eligible for garbage collection. Main purpose of this method is to perform any cleanup actions before the object is completely discarded by GC. However, the finalize method may take any action, including making this object available again to other threads. The finalize method of class Object does nothing; it simply returns normally. [node:read-more:link]
There are different kinds of references in Java like strong, soft, weak, phantom etc. When you create a normal object using the new keyword and then assign it to a regular type, you are creating a strong reference. Garbage collector will only collect an object if there are no strong references to that object. Less strong references include soft, weak and phantom, and they are defined in the java.lang.ref package.
String interning is a method of storing only one copy of each distinct string value. Strings in Java are immutable and hence this sharing is perfectly safe and give you better performance. The distinct values are stored in a fixed-size hashtable usually referred to as string intern pool or string pool. The single copy of each string is called its 'intern'. You can read more about the basics of String interning with examples @ string-interning-in-java-with-examples. [node:read-more:link]
This is a personal technical blog where we share our understanding on various concepts and is neither an official page or documentation for the products described here, nor the official views of the companies we work with.
Keywords used in this website are trademarks of their respective owners. This website is not affiliated with Oracle™ and/or any of the JEE frameworks like Spring™, Struts™, Hibernate™ and JSF™.
All contents and materials are provided freely without any warranty or liability and nothing within the site should be considered as professional advice. In any doubt, please ask, and we will try to help you based on our knowledge. Please let us know if you feel anything is not right here (including any copyright violation) and we will act upon it as fast as we can.