Say I have the code:
class Foobar {
Object item = null;
ItemInstantiator inst = new ItemInstantiator();
public instantiateItem() {
inst.instantiate(item);
}
}
class ItemInstantiator {
public instantiate(Object item) {
item = new Object();
}
}
Since the Foobar class has a live reference to the new object created in instantiate(), that new object should not be garbage collected after instantiate() finishes, right?
I ask because I am working on a project where it makes the most sense to declare an object in one class and instantiate the object in the method of another class. The problem is, once the instantiation finishes, the object is still null.