PDA

Click to See Complete Forum and Search --> : Garbage Collector??


Pirate
Nov 29th, 2002, 05:24 PM
Greetings ,

how can I know , when GC is raised or activated ??
thanx a lot

wyrd
Nov 30th, 2002, 02:20 AM
Well I don't think the Garbage Collector itself fires any events, but when an object is going through GC it calls the Finalize() method.

Athley
Nov 30th, 2002, 06:04 AM
If there is no way of knowing maybe you better control it by forcing the Garbage Collctions yourself.

But The finalize methods as Wyrd stated probably could be used as they don't fire until the object is collected.

Pirate
Nov 30th, 2002, 09:09 AM
guys

I believe that Finalize Method used to do specific job before releasing the object.I dunno if I'm wrong but ...
There sould be a way around forcing GC to fire as need!!!

Lethal
Nov 30th, 2002, 09:57 AM
You better have a pretty darn good reason to fire the GC from your code. Try using GC.Collect() in your code. It defintely hinders performance. Also, the Finalize() method is called right before the GC destroys the object. You should implement the Finalize() method in your class if you have unmanaged resources that need to be cleaned up. As you all probably know, the GC is nondeterministic. There is no way of knowing when the GC will come around and pick up the garbage. You should not have code that relies on this.

Pirate
Nov 30th, 2002, 10:04 AM
simply
in my WebBrowser project , I've created a lot of objects so I need to free the memory when these objects aren't needed so that doesn't affect the performance.
I guess MS didn't create GC at all:D

wyrd
Nov 30th, 2002, 01:38 PM
The GC automatically frees up memory for you. There is no need to do it yourself.

Also, I could be wrong on this, but I believe that even calling GC.Collect() won't necessarily free up all unused memory. You'll need to also call the GC.WaitForPendingFinalizers() to make sure everything marked for GC is cleaned up before continuing. But as Lethal pointed out, this hurts performance and is bad, bad, bad.

Pirate
Nov 30th, 2002, 03:39 PM
Okey wyrd, what is worst is the existance of the unused objects in momery , I know that GC is automatically does that but I really need to free up the mem .I will not wait till the system halt.:rolleyes:

Lethal
Nov 30th, 2002, 04:55 PM
Check out this article. Maybe it will help clear some things up for you..
http://www.gotdotnet.com/team/libraries/whitepapers%5Cresourcemanagement%5Cresourcemanagement.aspx

Pirate
Nov 30th, 2002, 07:41 PM
Frustrating:( :(
anyways thanx Lethal for the damn article....crying
**** Microsoft