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.
 

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

Back
Top