Results 1 to 10 of 10

Thread: Garbage Collector??

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Garbage Collector??

    Greetings ,

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

  2. #2
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    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.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    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.

  4. #4

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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!!!

  5. #5
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    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.

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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

  7. #7
    Member
    Join Date
    Sep 2002
    Location
    California
    Posts
    52
    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.

  8. #8

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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.

  9. #9
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Check out this article. Maybe it will help clear some things up for you..
    http://www.gotdotnet.com/team/librar...anagement.aspx

  10. #10

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Frustrating
    anyways thanx Lethal for the damn article....crying
    **** Microsoft

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width