I am confused about garbage collection process on objects.
object A = new object();
object B = A;
B.Dispose();
By calling a Dispose on variable B only, the created object will not be garbage collected as the object is still has referenced by A.
Now does the following code work same as above?
public static image Test1()
{
Bitmap A = new Bitmap();
return A;
}
Now I call this static function from some other method.
public void TestB()
{
Bitmap B = Test1();
B.Dispose();
}
The static function Test1 returned a reference to the Bitmap object. The reference is saved in another variable B. By calling a Dispose on B, the connection between B and object is lost but what happens to the reference that is passed from Test1. Will it remain active until the scope of the function TestB is finished?
Is there any way to dispose the reference that is passed from the static function immediately?