set reference to null ???

C

cmrchs

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...
 
T

Tomas Restrepo \(MVP\)

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;
 
C

cmrchs

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...
 
T

Tamas Demjen

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
 
W

Willy Denoyette [MVP]

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.
 

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

Top