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. How to reclaim the memory manually

How to reclaim the memory manually

Scheduled Pinned Locked Moved C#
performancetutorialquestion
7 Posts 2 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.
  • D Offline
    D Offline
    devin123
    wrote on last edited by
    #1

    Hi, I know GC does memory management manually. If i want to manually reclaim the memory of an object, how can I do it. Thanks Devin

    C 1 Reply Last reply
    0
    • D devin123

      Hi, I know GC does memory management manually. If i want to manually reclaim the memory of an object, how can I do it. Thanks Devin

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Of a single object, you cannot. In general, you can call GC.GarbageCollect() to force a garbage collection, however this is not recommended as the system is tuned to perform this at optimal times.


      My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      D 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Of a single object, you cannot. In general, you can call GC.GarbageCollect() to force a garbage collection, however this is not recommended as the system is tuned to perform this at optimal times.


        My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        D Offline
        D Offline
        devin123
        wrote on last edited by
        #3

        Then what does, GC.Collect() do what is differnce between them Devin

        C 1 Reply Last reply
        0
        • D devin123

          Then what does, GC.Collect() do what is differnce between them Devin

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Sorry, I was going from memory. I meant GC.Collect() From MSDN: GC.Collect()[^]: Forces garbage collection for all generations.


          My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

          D 1 Reply Last reply
          0
          • C Colin Angus Mackay

            Sorry, I was going from memory. I meant GC.Collect() From MSDN: GC.Collect()[^]: Forces garbage collection for all generations.


            My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

            D Offline
            D Offline
            devin123
            wrote on last edited by
            #5

            I think using GC.Collect we achieve finalization not memory reclaimation. Is I am right. Explain.

            C 1 Reply Last reply
            0
            • D devin123

              I think using GC.Collect we achieve finalization not memory reclaimation. Is I am right. Explain.

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              It will reclaim the memory. If an object requires it then the finaliser will be called first. The finalisation process is inefficient and objects that have finalisers will also have a Dispose() method. So, you should call Dispose() on an oject if it has that method. The Dispose() method will generally suppress the finalisation on that object making garbage collection more efficient.


              My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

              D 1 Reply Last reply
              0
              • C Colin Angus Mackay

                It will reclaim the memory. If an object requires it then the finaliser will be called first. The finalisation process is inefficient and objects that have finalisers will also have a Dispose() method. So, you should call Dispose() on an oject if it has that method. The Dispose() method will generally suppress the finalisation on that object making garbage collection more efficient.


                My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                D Offline
                D Offline
                devin123
                wrote on last edited by
                #7

                Thka colin for your help.

                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