Do inner classes cause a memory leak?
neal at gafter.com
Fri Jul 16 17:38:47 PDT 2010
On Fri, Jul 16, 2010 at 12:18 PM, Reinier Zwitserloot <
reinier at zwitserloot.com> wrote:
> Correct; the way the JLS currently specifies how anonymous inner classes
> work means they can NOT be static, and that a reference to the outer
> instance is passed into the inner instance even if it isn't actually
So far so good. The problem arises because javac generates unnecessary code
to store that parameter in a field of the anonymous class, and that's where
the memory leak occurs. Nothing in the language specification nor in any
compatibility issues requires the compiler to do that. It can and should be
fixed in javac.
More information about the lambda-dev