1. Concept
Memory leak in Java means that the memory of objects that are no longer used cannot be recycled, that is, a memory leak.
2. Reasons for leaks
For Java, we do not need (and have no way) to release memory ourselves. Useless objects are automatically cleared by GC, which also greatly simplifies Our programming work. However, in fact, sometimes some objects that are no longer used cannot be released in the GC's view, resulting in memory leaks.
3. Impact on the program
Memory leak is one of the main causes of application OOM. As we all know, the memory allocated by the Android system for each application is limited. When an application generates more memory leaks, it will inevitably cause the memory required by the application to exceed the memory limit allocated by the system, leading to memory overflow, thus Causes the application to crash.
4. Example
public class Simple { Object object; public void method1(){ object = new Object(); //...其他代码 } }
The above is the detailed content of What are the causes of java memory leaks. For more information, please follow other related articles on the PHP Chinese website!