From a naive point of view, it looks like declaring a local variables (ie., variables inside a method) as "final" could cause memory leak.
Eg.,
public static MyObject create()
{
final Long time = System.millis();
return new MyObject()
{
@Override public Long getTime() {return "Time is: " + time ; }
}
}
Clearly, the time
field has to be kept around even when create()
has returnt in order for getTime()
to work.
Ok, now say I have this method
public static int create()
{
final Long time = System.millis();
System.out.println(time);
return 2;
}
time
is not referenced in any inner class.
Is the object kept around after the method returns? Y
Thanks,