In the following code, does Nail
's reference to ypaw
end as soon as I exit the method someMethod
or is there potential for leakage? Also, once I exit class Dog
are all references to ypaw
gone or does the static reference inside Nail cause troubles? Note that ypaw
and mPaw
are the same object and I am wondering how long the object lives in memory due to the static reference. Of course assume the Garbage Collector executes at the appropriate time.
Class Dog{
private Paw ypaw;
//…..
public void someMethod(){
Nail nail = Nail.getInstance(ypaw);
}
}
Class Nail{
private static Paw mPaw;
public static Nail getInstance(Paw p){
mPaw = p;
return new Nail();
}
//…. other stuff
}
Edit
I mean to say that I have a single instance of Dog as myDog
and that my single instance of Nail
is through myDog
. What happens to mPaw
after myDog
dies (i.e. is gc'ed)?