The variable itself will go out of scope and be deallocated (as the call stack shrinks).

The object that the variable points to (the ArrayList) still has another reference pointing to it, so it will not be collected.

It will go away when no more references (such as your messages variable or field) exists.

This is not a memory leak.

In both scenarios, it is pointless to create the empty ArrayList before calling the function (and you should be asking yourself what happens to it once you receive the new one, just like you worried about temp. Don't worry, it's only pointless, not dangerous or "leaky").