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. .NET (Core and Framework)
  4. IDispose

IDispose

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
5 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.
  • D Offline
    D Offline
    D N
    wrote on last edited by
    #1

    what is the significance of IDispose Interface?

    C C 2 Replies Last reply
    0
    • D D N

      what is the significance of IDispose Interface?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Any object that holds on to things that need to be cleaned up will impliment IDisposable, and you should call the Dispose method on such items when you're finished with them. Common examples would include pretty much anything in the System.Drawing namespaces, or anything else that holds an unmanaged handle of some sort. We have this interface because a garbage collected system cannot support deterministic destruction. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • D D N

        what is the significance of IDispose Interface?

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

        To add to what Christian said I would also recomment that you use using{} when you use an object that implements the IDisposable interface and it will naturally go out of scope at the end of the method. For example:

        using(SomeDisposableClass disposableInstance = new SomeDisposableClass())
        {
        // Do stuff with the disposableInstance
        }

        When the using block is completed the Dispose() method will be called. It will also clean up the object if an exception is causing the stack to unwind.


        My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

        C 1 Reply Last reply
        0
        • C Colin Angus Mackay

          To add to what Christian said I would also recomment that you use using{} when you use an object that implements the IDisposable interface and it will naturally go out of scope at the end of the method. For example:

          using(SomeDisposableClass disposableInstance = new SomeDisposableClass())
          {
          // Do stuff with the disposableInstance
          }

          When the using block is completed the Dispose() method will be called. It will also clean up the object if an exception is causing the stack to unwind.


          My: Blog | Photos "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          That's if he's using C#, I don't believe VB.NET supports it. Christian Graus - Microsoft MVP - C++

          L 1 Reply Last reply
          0
          • C Christian Graus

            That's if he's using C#, I don't believe VB.NET supports it. Christian Graus - Microsoft MVP - C++

            L Offline
            L Offline
            Leather99
            wrote on last edited by
            #5

            It is supported in VB.NET 2.0, so you will be ok if thats what you are working with.


            MCSD(VB6/SQL7) MCAD(C#/SQL2000) MCSD(C#/SQL2000)

            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