Cause Analysis
1. If the anonymous inner class is not referenced, there will be a chance for recycling when the objects of the anonymous inner class are used up.
2. If the inner class is only referenced in the outer class, when the outer class is no longer referenced, the outer class and the inner class can be recycled through GC.
When the inner class reference is referenced by other classes other than the outer class, the inner class and the outer class cannot be recycled by GC. Even if the outer class is not referenced, the inner class still has a reference to the outer class).
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
The above is the detailed content of What is the cause of Java inner class memory leak?. For more information, please follow other related articles on the PHP Chinese website!