reference type garbage collection

G

Guest

If a reference to an object or an array is set to null, will the object/array
and all of it’s members/elements be garbage collected as well (Assuming that
no other references are held on the members/elements, and none of these
members/elements hold references to unmanaged resources.)?

For example:

public class A
{
public A(){}
}
..
..
..
A[] A_array = new A[5];

for(int i = 0; i < 5; i++)
{
A_array = new A();
}

A_array = null; // Will all of A_array’s elements be garbage collected here?


thanks
 
J

Joanna Carter [TeamB]

"Ivan" <[email protected]> a écrit dans le message de (e-mail address removed)...

| If a reference to an object or an array is set to null, will the
object/array
| and all of it's members/elements be garbage collected as well (Assuming
that
| no other references are held on the members/elements, and none of these
| members/elements hold references to unmanaged resources.)?

Strictly, when an object reference is nulled, assuming no other references
exist, the object becomes available for GC but there is no guarantee when
the GC will occur. In practice, it could be fairly immediate but ...

Joanna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top