class A {}
class B {
static A someReference = null;
void foo () {
// does calling this function many times create new objects, or all objects will point to one memory.
someReference = new A;
}
}
isn’t making a reference static mean that it will not be able to point to new memory location.?
Thank you.
Calling
foo()resulting innew A()multiple times will create new instance ofAevery time.However previous instance becomes eligible for garbage collection (since
someReferenceis no longer pointing to it) and will be removed shortly during next garbage collection cycle.