Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 45783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:51:48+00:00 2026-05-10T15:51:48+00:00

Although I do understand the serious implications of playing with this function (or at

  • 0

Although I do understand the serious implications of playing with this function (or at least that’s what I think), I fail to see why it’s becoming one of these things that respectable programmers wouldn’t ever use, even those who don’t even know what it is for.

Let’s say I’m developing an application where memory usage varies extremely depending on what the user is doing. The application life cycle can be divided into two main stages: editing and real-time processing. During the editing stage, suppose that billions or even trillions of objects are created; some of them small and some of them not, some may have finalizers and some may not, and suppose their lifetimes vary from a very few milliseconds to long hours. Next, the user decides to switch to the real-time stage. At this point, suppose that performance plays a fundamental role and the slightest alteration in the program’s flow could bring catastrophic consequences. Object creation is then reduced to the minimum possible by using object pools and the such but then, the GC chimes in unexpectedly and throws it all away, and someone dies.

The question: In this case, wouldn’t it be wise to call GC.Collect() before entering the second stage?

After all, these two stages never overlap in time with each other and all the optimization and statistics the GC could have gathered would be of little use here…

Note: As some of you have pointed out, .NET might not be the best platform for an application like this, but that’s beyond the scope of this question. The intent is to clarify whether a GC.Collect() call can improve an application’s overall behaviour/performance or not. We all agree that the circumstances under which you would do such a thing are extremely rare but then again, the GC tries to guess and does it perfectly well most of the time, but it’s still about guessing.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:51:49+00:00Added an answer on May 10, 2026 at 3:51 pm

    From Rico’s Blog…

    Rule #1

    Don’t.

    This is really the most important rule. It’s fair to say that most usages of GC.Collect() are a bad idea and I went into that in some detail in the orginal posting so I won’t repeat all that here. So let’s move on to…

    Rule #2

    Consider calling GC.Collect() if some non-recurring event has just happened and this event is highly likely to have caused a lot of old objects to die.

    A classic example of this is if you’re writing a client application and you display a very large and complicated form that has a lot of data associated with it. Your user has just interacted with this form potentially creating some large objects… things like XML documents, or a large DataSet or two. When the form closes these objects are dead and so GC.Collect() will reclaim the memory associated with them…

    So it sounds like this situation may fall under Rule #2, you know that there’s a moment in time where a lot of old objects have died, and it’s non-recurring. However, don’t forget Rico’s parting words.

    Rule #1 should trump Rule #2 without strong evidence.

    Measure, measure, measure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Tcl has a command [file type $filename] that will return… May 11, 2026 at 10:51 am
  • added an answer You cannot create an index that will speed up any… May 11, 2026 at 10:51 am
  • added an answer This JavaScript tool does just what you need: http://www.azarask.in/blog/post/socialhistoryjs/ May 11, 2026 at 10:51 am

Related Questions

Although I do understand the serious implications of playing with this function (or at
I admit this is not strictly a programming question, although I do use my
In Python specifically, how do variables get shared between threads? Although I have used
Although I'm specifically interested in web application information, I would also be somewhat curious
Although I don't have an iPhone to test this out, my colleague told me
Although I played with it before, I'm finally starting to use Dvorak (Simplified) regularly.
Although I grasp the concept of Bitwise Operators, I can't say that I have
Although I'm doubtful, I'm curious as to whether it's possible to extract primitive-type template
Although I know how to build a DOM the long, arduous way using the
Although I deeply fell in love with the MVVM pattern there seem to be

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.