Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. garbage collector

garbage collector

Scheduled Pinned Locked Moved C#
helpquestioncareer
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalyan_2416
    wrote on last edited by
    #1

    hi all i was asked in interview how often the garbage collector i.e. gc.collect() will get invoked i know why? what? about garbage collectore but interviewer asked me will it be for every 5 minutes the method invokes can anyone help me... bye

    J N P 3 Replies Last reply
    0
    • K kalyan_2416

      hi all i was asked in interview how often the garbage collector i.e. gc.collect() will get invoked i know why? what? about garbage collectore but interviewer asked me will it be for every 5 minutes the method invokes can anyone help me... bye

      J Offline
      J Offline
      J a a n s
      wrote on last edited by
      #2

      When 1) a memory allocation request exceeds the current generation 0 segment capacity (or because of an exlicit call to GC.Collect) and 2) the object is no longer reachable. If we exclude GC.Collect calls, this means that a GC will only occur on allocation. In other words, objects may well be ready to be released but no allocations are made, meaning no GCs will occur, so memory usage will stay flat.

      *jaans

      K 1 Reply Last reply
      0
      • K kalyan_2416

        hi all i was asked in interview how often the garbage collector i.e. gc.collect() will get invoked i know why? what? about garbage collectore but interviewer asked me will it be for every 5 minutes the method invokes can anyone help me... bye

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        kalyan_2416 wrote:

        how often the garbage collector i.e. gc.collect() will get invoked

        Gc.Collect() will invoke garbage collector immediately. But AFAIK, we can't predict the timings when GC invoked when Collect() is not used. I guess it will be invoked when a cleanup is required.

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        K M 2 Replies Last reply
        0
        • K kalyan_2416

          hi all i was asked in interview how often the garbage collector i.e. gc.collect() will get invoked i know why? what? about garbage collectore but interviewer asked me will it be for every 5 minutes the method invokes can anyone help me... bye

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Garbage collection in .NET is not based on frequency. Instead, it is a sophisticated algorithm that will collect the object at some point after the object has become eligible for collection. Have a read of this[^] article.

          Deja View - the feeling that you've seen this post before.

          1 Reply Last reply
          0
          • J J a a n s

            When 1) a memory allocation request exceeds the current generation 0 segment capacity (or because of an exlicit call to GC.Collect) and 2) the object is no longer reachable. If we exclude GC.Collect calls, this means that a GC will only occur on allocation. In other words, objects may well be ready to be released but no allocations are made, meaning no GCs will occur, so memory usage will stay flat.

            *jaans

            K Offline
            K Offline
            kalyan_2416
            wrote on last edited by
            #5

            k thanx got it

            1 Reply Last reply
            0
            • N N a v a n e e t h

              kalyan_2416 wrote:

              how often the garbage collector i.e. gc.collect() will get invoked

              Gc.Collect() will invoke garbage collector immediately. But AFAIK, we can't predict the timings when GC invoked when Collect() is not used. I guess it will be invoked when a cleanup is required.

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

              K Offline
              K Offline
              kalyan_2416
              wrote on last edited by
              #6

              nice quote yup the other friend also says what u have guessed thanx bye

              1 Reply Last reply
              0
              • N N a v a n e e t h

                kalyan_2416 wrote:

                how often the garbage collector i.e. gc.collect() will get invoked

                Gc.Collect() will invoke garbage collector immediately. But AFAIK, we can't predict the timings when GC invoked when Collect() is not used. I guess it will be invoked when a cleanup is required.

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

                M Offline
                M Offline
                Mark Churchill
                wrote on last edited by
                #7

                IIRC explicitly calling GC.Collect() is generally a bad idea. The deal is that it will encourage the garbage collector to promote objects that survive collection to a higher generation. The higher generations are collected less aggressively - which has obvious performance implications.

                Mark Churchill Director Dunn & Churchill

                P 1 Reply Last reply
                0
                • M Mark Churchill

                  IIRC explicitly calling GC.Collect() is generally a bad idea. The deal is that it will encourage the garbage collector to promote objects that survive collection to a higher generation. The higher generations are collected less aggressively - which has obvious performance implications.

                  Mark Churchill Director Dunn & Churchill

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  You recall correctly. There aren't many occassions, (I can't think or any offhand), where you should call it - let the runtime determine this.

                  Deja View - the feeling that you've seen this post before.

                  L 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    You recall correctly. There aren't many occassions, (I can't think or any offhand), where you should call it - let the runtime determine this.

                    Deja View - the feeling that you've seen this post before.

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    You may consider GC.Collect() when you want to get an optimal and/or repeatable starting condition, examples: - application has busy and idle periods, and wants to off-load as much work as possible from the busy to the idle periods - application is going to be observed/measured (as in the Setup method when using NUnit), say for performance measurements. And yes, these are exceptional situations.

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups