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. explicit deletion of object

explicit deletion of object

Scheduled Pinned Locked Moved C#
csharp
4 Posts 4 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.
  • L Offline
    L Offline
    leopard447
    wrote on last edited by
    #1

    is there any method to delete an object in c# explicitly or i have to set obeject to null and then wait for GC to delete it.v skhurram

    L S 2 Replies Last reply
    0
    • L leopard447

      is there any method to delete an object in c# explicitly or i have to set obeject to null and then wait for GC to delete it.v skhurram

      L Offline
      L Offline
      leoiser
      wrote on last edited by
      #2

      Use dispose method obj.Dispose(); Thanks

      S 1 Reply Last reply
      0
      • L leoiser

        Use dispose method obj.Dispose(); Thanks

        S Offline
        S Offline
        seeitsharper
        wrote on last edited by
        #3

        There really is no 'Explicit' deletion of managed objects in .net like there are in other languages such as c++. You will have to always wait for th GC to do it stuff. obj.Dispose is just a clean up method really designed for releasing unmanged resources like handles. The Dispose Pattern discusses disposing of objects


        Keep your eyes open, you might spot alternatives.

        1 Reply Last reply
        0
        • L leopard447

          is there any method to delete an object in c# explicitly or i have to set obeject to null and then wait for GC to delete it.v skhurram

          S Offline
          S Offline
          Scott Dorman
          wrote on last edited by
          #4

          There is no way to "delete" an object in .NET like you do in C or C++. The closest you can get is to call the Dispose method if it's available (or the appropriate equivalent since some classes have a Close method that actualy does the same work as Dispose) and wait for the GC to delete it. Check out this article Implementing IDisposable and the Dispose Pattern Properly[^] for more details on how to use Disopse.

          ----------------------------- In just two days, tomorrow will be yesterday. http://geekswithblogs.net/sdorman

          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