Question of the day :Day 8

Question of the day.

This is a perplexing question that has been asked to me by an interviewer long back.I thought of sharing it with u. He asked me about the difference between string and string builder.I gave him an impressive answer.The answer that i gave him was efficient memory management that can be achieved using string builder.
You can view my previous post on String and String Builder for more details.
Then he asked me a question linking garbage collector to it. Since garbage collector automatically remove unwanted objects. why do we need a string builder?

I told him that garbage collector is unpredictable. The moment when the garbage is actually collected can be unpredictable, resulting in stalls scattered throughout a session. he was not satisfied with my answer.So today’s Question is all about Garbage collector.We know the advantages of using Garbage collector.But it has some disadvantages too. lets have a detailed look on it.


What are the Disadvantages of Garbage Collector?


  • Time Consumption
  • The point when the garbage is actually collected can be unpredictable, resulting in stalls scattered throughout a session.
  • Garbage collection consumes computing resources in deciding what memory is to be freed, reconstructing facts that may have been known to the programmer.
  • In virtual memory environments typical of modern desktop computers, it can be difficult for the garbage collector to notice when collection is needed, resulting in large amounts of accumulated garbage, a long, disruptive collection phase, and other programs’ data swapped out.
  • Perhaps the most significant problem is that programs that rely on garbage collectors often exhibit poor locality (interacting badly with cache and virtual memory systems), occupy more address space than the program actually uses at any one time, and touch otherwise idle pages. These may combine in a phenomenon called thrashing, in which a program spends more time copying data between various grades of storage than performing useful work. They may make it impossible for a programmer to reason about the performance effects of design choices, making performance tuning difficult. They can lead garbage-collecting programs to interfere with other programs competing for resources

  • HappyCoding ! 😉


    Leave a Reply

    Fill in your details below or click an icon to log in: Logo

    You are commenting using your account. Log Out /  Change )

    Google photo

    You are commenting using your Google account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s

    %d bloggers like this: