Garbage Collector

  • Thread starter Thread starter C# Learner
  • Start date Start date
C

C# Learner

This is probably a silly question but I'll ask to be sure.

Say I have a constructor that looks like this:

public MyClass()
{
items = new string[10];
for (int i = 0; i < items.Length; ++i) {
items = new String();
}
}

Is the following then necessary?

~MyClass()
{
for (int i = 0; i < items.Length; ++i) {
items = null;
}
}
 
No even assuming a more 'real-world' sample than the one you've given here..
The GC will mark all CLR-managed objects for collection that don't have a
'live' reference (reference that is still accessible in all stack frames of
currently running code). You don't have to do any manual work null-ing them
out.

Richard
 
Richard said:
No even assuming a more 'real-world' sample than the one you've given here..
The GC will mark all CLR-managed objects for collection that don't have a
'live' reference (reference that is still accessible in all stack frames of
currently running code). You don't have to do any manual work null-ing them
out.

Richard

Alright, thanks.
 
Back
Top