In Java can making a local variable final in a non-static method that is called many times cause a memory leak? -
for example lets have:
public void dothis() { final foo foo = foo.getinstance(); ... initialize foo somehow... baz(bar.getinstance(foo)); // adds bar instance ... bar popped list, used, , disposed of... }
can memory leak occur scenario?
i'm not understanding final local variable means. mean local variable cannot reassigned, , it? declaring final put somewhere in java heap/memory such it's instance variable different/unique? since inner/nested class can use final local variable, not non-final local variable?
no. if there wasn't memory leak without final
, there won't 1 final
.
the only thing final
local variable (in java 8)1 prevent assigning variable more once.
1 in java 7 , earlier, there effect had nothing memory leaks.
Comments
Post a Comment