Inspectopedia Help

Return of instance of anonymous, local or inner class

Reports return statements that return an instance of an anonymous, local, or inner class. Such instances keep an implicit reference to the outer instance, which can prevent the outer instance from being garbage-collected. Any caller of a method returning such an instance might cause a memory leak by holding on to the instance returned.

Configure the inspection:

  • Use the Ignore returns from non-public methods option to ignore returns from protected or package-private methods. Returns from private methods are always ignored.

Inspection options




Ignore returns from non-public methods



Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3


Java, 233.SNAPSHOT

Last modified: 13 July 2023