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. Managed C++/CLI
  4. What is special about Dispose() methods?

What is special about Dispose() methods?

Scheduled Pinned Locked Moved Managed C++/CLI
visual-studioquestioncsharpc++graphics
6 Posts 3 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.
  • B Offline
    B Offline
    BuckBrown
    wrote on last edited by
    #1

    Hi, I am using Visual Studio C++/CLI. I am now playing around with the System::Drawing::Font class and I have seen Microsoft examples that use Dispose() but when I try to invoke the System::Drawing::Font::Dispose() function the compiler gives me an "error C2039: 'Dispose' : is not a member of 'System::Drawing::Font'". Does anyone know why this happens? The intellisense shows that the Dispose() method is a member of the Font class (as well as the Microsoft docs). Thanks Buck

    I M 2 Replies Last reply
    0
    • B BuckBrown

      Hi, I am using Visual Studio C++/CLI. I am now playing around with the System::Drawing::Font class and I have seen Microsoft examples that use Dispose() but when I try to invoke the System::Drawing::Font::Dispose() function the compiler gives me an "error C2039: 'Dispose' : is not a member of 'System::Drawing::Font'". Does anyone know why this happens? The intellisense shows that the Dispose() method is a member of the Font class (as well as the Microsoft docs). Thanks Buck

      I Offline
      I Offline
      iddqd515
      wrote on last edited by
      #2

      Dispose() is a function inherited from the IDisposable interface. Its meant to implement the "Dispose pattern" to enable some form of immediate destructors in managed code. In C# you can call Dispose() on objects that will perform some clean up functions (like closing streams and such). In C++/CLI Dispose() is mapped to the class destructor by the compiler. You can't explicitly invoke Dispose() (nor write one). Instead, if an object encapsulating a resource needs some clean up done immediately (rather than waiting for the garbage collector) call either a Close() type function (which itself should only call the destructor I believe) or use delete (or declare the variable with stack semantics and have the destructor called automatically when the variable goes out of scope).

      B 1 Reply Last reply
      0
      • B BuckBrown

        Hi, I am using Visual Studio C++/CLI. I am now playing around with the System::Drawing::Font class and I have seen Microsoft examples that use Dispose() but when I try to invoke the System::Drawing::Font::Dispose() function the compiler gives me an "error C2039: 'Dispose' : is not a member of 'System::Drawing::Font'". Does anyone know why this happens? The intellisense shows that the Dispose() method is a member of the Font class (as well as the Microsoft docs). Thanks Buck

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        This bit me a bit when I recently migrated to VS 2005. Here's an article that may help (even though the article is about porting to 2005, it contains relevant info about destructors and Dispose):  Changes in Destructor Semantics[^] Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        B 1 Reply Last reply
        0
        • I iddqd515

          Dispose() is a function inherited from the IDisposable interface. Its meant to implement the "Dispose pattern" to enable some form of immediate destructors in managed code. In C# you can call Dispose() on objects that will perform some clean up functions (like closing streams and such). In C++/CLI Dispose() is mapped to the class destructor by the compiler. You can't explicitly invoke Dispose() (nor write one). Instead, if an object encapsulating a resource needs some clean up done immediately (rather than waiting for the garbage collector) call either a Close() type function (which itself should only call the destructor I believe) or use delete (or declare the variable with stack semantics and have the destructor called automatically when the variable goes out of scope).

          B Offline
          B Offline
          BuckBrown
          wrote on last edited by
          #4

          Thanks.

          1 Reply Last reply
          0
          • M Mark Salsbery

            This bit me a bit when I recently migrated to VS 2005. Here's an article that may help (even though the article is about porting to 2005, it contains relevant info about destructors and Dispose):  Changes in Destructor Semantics[^] Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            B Offline
            B Offline
            BuckBrown
            wrote on last edited by
            #5

            Thanks.

            M 1 Reply Last reply
            0
            • B BuckBrown

              Thanks.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Thank you for bringing the subject up....it reminded me I needed to finish some porting of my code from managed extensions (VS 2003). In case you haven't already come across these: Dispose from the .NET framework point-of-view: Implementing Finalize and Dispose to Clean Up Unmanaged Resources[^] and specifically for Managed C++: Destructors and Finalizers in Visual C++[^] Cheers, Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              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