Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

set reference to null ???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
cmrchs@yahoo.com - 22 Jun 2005 10:59 GMT
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
Tomas Restrepo \(MVP\) - 22 Jun 2005 12:17 GMT
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;

Signature

Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/

cmrchs@yahoo.com - 22 Jun 2005 12:39 GMT
and....

car2 = nullptr

... doesn't work either

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

Any other posibillities ?

thanks
Chris
Tamas Demjen - 22 Jun 2005 17:29 GMT
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

> and....
>
[quoted text clipped - 8 lines]
> thanks
> Chris
Willy Denoyette [MVP] - 22 Jun 2005 19:23 GMT
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.

> It will be garbage collected when the system feels it has no more
> resources. It may never happen. You have no control about that.
[quoted text clipped - 14 lines]
>> thanks
>> Chris

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.