473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Garbage Collector

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[i] = new String();
}
}

Is the following then necessary?

~MyClass()
{
for (int i = 0; i < items.Length; ++i) {
items[i] = null;
}
}
Nov 15 '05 #1
3 1314
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

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"C# Learner" <cs****@learner.here> wrote in message
news:e0*************@tk2msftngp13.phx.gbl...
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[i] = new String();
}
}

Is the following then necessary?

~MyClass()
{
for (int i = 0; i < items.Length; ++i) {
items[i] = null;
}
}

Nov 15 '05 #2
Richard A. Lowe wrote:
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.
Nov 15 '05 #3
I probably should have said "in any stack frame" .. .but you get the idea.

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"C# Learner" <cs****@learner.here> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
Richard A. Lowe wrote:
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.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
13
by: Mingnan G. | last post by:
Hello everyone. I have written a garbage collector for standard C++ application. It has following main features. 1) Deterministic Finalization Providing deterministic finalization, the system...
28
by: Goalie_Ca | last post by:
I have been reading (or at least googling) about the potential addition of optional garbage collection to C++0x. There are numerous myths and whatnot with very little detailed information. Will...
142
by: jacob navia | last post by:
Abstract -------- Garbage collection is a method of managing memory by using a "collector" library. Periodically, or triggered by an allocation request, the collector looks for unused memory...
8
by: Paul.Lee.1971 | last post by:
Hi everyone, A program that I'm helping to code seems to slow down drastically during initialisation, and looking at the profiling graph, it seems to be the garbage collector thats slowing things...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.