String result = foo() + arg; -> 3 created : foo() is one, arg is one. (foo() + arg) is 1
result += boo(); -> 2 created: boo() is one, (result +boo) is1.
System.out.println("result = " + result); 2: created "result=" is 1, ("result="+result) is 1
-->there is total 7 instance of String object now.
-->if GC is at this point only foo(), boo() and ((foo() + arg))," and (("result = " + result)) and "result = " will be gone.
what where variable result is pointing to will not get GCed since it is not considered orphan.
(result +boo) will not get GC since it is stiing being pointed.
arg is not set to null so jvm will not got GC the refering object
now pay me with 200K :)
result += boo(); -> 2 created: boo() is one, (result +boo) is1.
System.out.println("result = " + result); 2: created "result=" is 1, ("result="+result) is 1
-->there is total 7 instance of String object now.
-->if GC is at this point only foo(), boo() and ((foo() + arg))," and (("result = " + result)) and "result = " will be gone.
what where variable result is pointing to will not get GCed since it is not considered orphan.
(result +boo) will not get GC since it is stiing being pointed.
arg is not set to null so jvm will not got GC the refering object
now pay me with 200K :)