473,399 Members | 2,278 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,399 software developers and data experts.

creating a new instance

Hello!!

Here I create a new instance t of class Test and pass the referenc to method
goo.
When this method foo eventually finish will this instace t go out of scope
and be garbage collected.?
If not exactly what must occur so that the instance t be garbage collected.

void foo()
{
Test t = new Test;
goo(t);
}

//Tony
Jul 18 '05 #1
4 7347

"Tony Johansson" <jo*****************@telia.com> skrev i en meddelelse
news:QC*********************@newsc.telia.net...
Hello!!

Here I create a new instance t of class Test and pass the referenc to
method goo.
When this method foo eventually finish will this instace t go out of scope
and be garbage collected.?
If not exactly what must occur so that the instance t be garbage
collected.

void foo()
{
Test t = new Test;
goo(t);
}

//Tony


Short anwer: YES.......

But if you want to be sure, then set t = null; after the call to goo
Claus
Jul 18 '05 #2
> But if you want to be sure, then set t = null; after the call to goo

And (assuming everything is syncronous) if you REALLY want to be in
control, call the garbage collector explicitly:

System.gc();

/Casper
Jul 18 '05 #3
Claus Petersen wrote:
"Tony Johansson" <jo*****************@telia.com> skrev i en meddelelse
news:QC*********************@newsc.telia.net...
Hello!!

Here I create a new instance t of class Test and pass the referenc to
method goo.
When this method foo eventually finish will this instace t go out of scope
and be garbage collected.?
If not exactly what must occur so that the instance t be garbage
collected.

void foo()
{
Test t = new Test;
goo(t);
}

//Tony

Short anwer: YES.......

But if you want to be sure, then set t = null; after the call to goo
Claus


It depends also on what goo() does. If goo() stores a reference
somewhere t may not be eligible for GC.

Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #4
"Casper B" <ca****@jbr.dk> wrote in message
news:42*********************@dread12.news.tele.dk. ..
But if you want to be sure, then set t = null; after the call to goo


And (assuming everything is syncronous) if you REALLY want to be in
control, call the garbage collector explicitly:

System.gc();

/Casper


.... Except that the GC will never let you be in control. The call to
System.gc() is only a _suggestion_ to JVM to run the garbage collector. The
JVM may or may not do it on your request. Also, setting t to null is
superfluous. Once t goes out of scope in the given example, all references
to it are gone, and it becomes eligible for the collection - whether it was
nulled out or not.
Jul 18 '05 #5

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

Similar topics

2
by: jm | last post by:
I have a Form1 and two class files. In the first class, I call the second class. The second class references the Form1 notifyicon and changes the icon. It works. The problems is, however,...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
3
by: Mag | last post by:
I am trying to install onDemand content manager for Linux I am looking at these instructions http://publib.boulder.ibm.com/infocenter/cmod/v8r3m0//topic/com.ibm.ondemand.mp.doc/ars1i07135.htm ...
1
by: vijju | last post by:
Hi all ! I'm an amateur to DB2.I installed DB2 ESE trial edition on my system.It was all going well and suddenly when i was trying to create an instance, i faced a problem which i listed it below....
7
by: Brett Romero | last post by:
I need a static version of a class that can be referenced anywhere as a singleton and the same class that can be used as instances. Can this be done without basically creating the same class twice...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
19
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender,...
3
by: Peter Morris | last post by:
Hi all Let's say I am creating a model to represent classes and properties. In addition to this I need instances of classes and values for those properties. KEY: (AssociationEndName)
4
by: =?Utf-8?B?Z3JlZw==?= | last post by:
I am trying to create an instance of a 3rd party COM component, and I'm getting an error. I've opened a ticket with this vendor as well, but I want to approach it from the C# .NET side to make...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
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.