What if there is a global constant (Object, Array, Map, etc.) defined. And in some method we create a new variable that references this global constant, which is a shallow copy.
Does this shallow copy get garbage collected after exiting the method execution scope? From what I understand global variables do not get garbage collected as they are at the root. And the shallow copy references the same object reference in the heap as the global variable.
I think it does not create a new memory allocation in the Heap since it is not a deep copy, but the Shallow copy would still live on the stack with reference to same memory reference in the heap?
I am wondering if this causes memory leaks?
I am not sure how to see what gets garbage collected through the mark sweep algorithms