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

set reference to null ???

Hi,

how do you set a handle to 0, so that the object will be garbage collected ?

Car^ car2 = gcnew Car();

car2 = null; // NOPE
car2 = 0; // NOPE
thanks
Christian

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 17 '05 #1
4 1250
Chris,
how do you set a handle to 0, so that the object will be garbage collected
?
Actually, you don't need it to set it to null explicitly for it to be
garbage collected.

Car^ car2 = gcnew Car();

car2 = null; // NOPE
car2 = 0; // NOPE


Try:
car2 = nullptr;
--
Tomas Restrepo
to****@mvps.org
http://www.winterdom.com/
Nov 17 '05 #2
and....

car2 = nullptr

.... doesn't work either

'cause it does not mark the object for garbage collection :-((

Any other posibillities ?

thanks
Chris

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 17 '05 #3
It will be garbage collected when the system feels it has no more
resources. It may never happen. You have no control about that.

There's a way to enforce garbage collection (GC::Collect()), but you're
not supposed to do that. Let the system make its own decision.

Tom

cm****@yahoo.com wrote:
and....

car2 = nullptr

... doesn't work either

'cause it does not mark the object for garbage collection :-((

Any other posibillities ?

thanks
Chris

Nov 17 '05 #4
Note that the GC kicks in when there are certain managed heap thresholds
reached, not when the system feels it has no more resources.
The thresholds vary largely between CLR versions (Workstation,Server) and GC
versions (concurrent, pre-emptive) and also between releases (v1.x, v2.0),
and they are dynamically adapting according the usage pattern. For instance,
the threshold decreases with an increasing allocation frequency (more
collections), but this is not the sole criterion to adapt the threshold
levels. In general one can say that the gen0 (this is the place where all,
except the large objects, start their life) threshold stay's below 1Mb on
v1.x and below 3Mb for v2.0.
The same applies to gen1 and gen2, of course the thresholds are getting
larger for each older generation.

Willy.

"Tamas Demjen" <td*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
It will be garbage collected when the system feels it has no more
resources. It may never happen. You have no control about that.

There's a way to enforce garbage collection (GC::Collect()), but you're
not supposed to do that. Let the system make its own decision.

Tom

cm****@yahoo.com wrote:
and.... car2 = nullptr

... doesn't work either

'cause it does not mark the object for garbage collection :-((

Any other posibillities ?

thanks
Chris

Nov 17 '05 #5

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

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
15
by: David Fisher | last post by:
I have been encouraged by someone else to use a reference rather than a pointer as an "out" parameter to a function, eg. void doStuff(Thing &out1, Thing &out2) as opposed to: void...
15
by: JKop | last post by:
Does that Standard explicitly forbid the initiation of a null reference? Is there anything wrong with the following code?: void Blah( std::string const &k ) { if ( !&k ) return; // work with...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
5
by: Boniek | last post by:
Hi I define a public property in a new form and I can see this property in table of Properties in Visual. How I can hide this property to see only in code ? Thank's Boniek
0
by: Stephen Cairns | last post by:
I have the following rpx file in a .Net solution and I am getting the following build errors which are driving me crazy and ive no idea where I have went wrong. The build errors I'm getting are as...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
27
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
2
by: toton | last post by:
Hi, This is continuation of topic pointer & reference doubt. http://groups.google.com/group/comp.lang.c++/browse_thread/thread/df84ce6b9af561f9/76304d7d77f6ccca?lnk=raot#76304d7d77f6ccca But I...
3
by: pleaseexplaintome_2 | last post by:
using the code below (some parts not included), I create a new excel workbook with spreadheets. I then want to delete a spreadsheet, but a reference remains open and excel stays in task manager...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.