473,414 Members | 1,686 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,414 software developers and data experts.

Garbage collection.....

10
The following code creates one array and one string object. How many references to those objects exist after the code executes? Is either object eligible for garbage collection?
Expand|Select|Wrap|Line Numbers
  1.     ...
  2.     String[] students = new String[10];
  3.     String studentName = "Peter Parker";
  4.     students[0] = studentName;
  5.     studentName = null;
  6.     ...
  7.  
Answer 2: There is one reference to the students array and that array has one reference to the string Peter Parker. Neither object is eligible for garbage collection.


Q:- A program can set all references to an object to null so that it becomes eligible for garbage collection. Right?....But here we have set studentName to 'null' then why in answer its written "Neither object is eligible for garbage collection. "????
Sep 18 '08 #1
2 1745
JosAH
11,448 Expert 8TB
The following code creates one array and one string object. How many references to those objects exist after the code executes? Is either object eligible for garbage collection?
Expand|Select|Wrap|Line Numbers
  1.     ...
  2.     String[] students = new String[10];
  3.     String studentName = "Peter Parker";
  4.     students[0] = studentName;
  5.     studentName = null;
  6.     ...
  7.  
Answer 2: There is one reference to the students array and that array has one reference to the string Peter Parker. Neither object is eligible for garbage collection.

Q:- A program can set all references to an object to null so that it becomes eligible for garbage collection. Right?....But here we have set studentName to 'null' then why in answer its written "Neither object is eligible for garbage collection. "????
After execution of line #1 the students reference points to an array of ten String
references. Those references don't point to anything yet.
After execution of line #2 the studentName reference points to string "Peter Parker".
After execution of line #3 the first reference in the array also points to that same
string.
After execution of line #4 studentName doesn't point to anything anymore.

So at the end 'students' points to an array of ten references; all of them are null
except for the first one: it points to a String "Peter Parker".

kind regards,

Jos
Sep 18 '08 #2
Vneha
10
Thanks.

I got it.

Regards,

Neha
Sep 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob | last post by:
Are there any known applications out there used to test the performance of the .NET garbage collector over a long period of time? Basically I need an application that creates objects, uses them, and...
6
by: Ganesh | last post by:
Is there a utility by microsoft (or anyone) to force garbage collection in a process without have access to the process code. regards Ganesh
11
by: Rick | last post by:
Hi, My question is.. if Lisp, a 40 year old language supports garbage collection, why didn't the authors of C++ choose garbage collection for this language? Are there fundamental reasons behind...
34
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple,...
5
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000...
8
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by...
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...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
350
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.