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. Destructor or no destructor ??

Destructor or no destructor ??

Scheduled Pinned Locked Moved Managed C++/CLI
c++question
6 Posts 3 Posters 17 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.
  • A Offline
    A Offline
    Albert Pascual
    wrote on last edited by
    #1

    In MC++ should we always delete the destructor and the implement the Finalize function or we should never do anything? I am still a little confused about if to leave the desctructor or not Experts?!!? :confused: Al

    J 1 Reply Last reply
    0
    • A Albert Pascual

      In MC++ should we always delete the destructor and the implement the Finalize function or we should never do anything? I am still a little confused about if to leave the desctructor or not Experts?!!? :confused: Al

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      If it behaves like C# the destructor is treated as a Finalize method.... Wonder what would happen if you define both :) James Simplicity Rules!

      A 1 Reply Last reply
      0
      • J James T Johnson

        If it behaves like C# the destructor is treated as a Finalize method.... Wonder what would happen if you define both :) James Simplicity Rules!

        A Offline
        A Offline
        Albert Pascual
        wrote on last edited by
        #3

        The question may also be: What happens if I don't define a destructor what so ever? Al:confused:

        J 1 Reply Last reply
        0
        • A Albert Pascual

          The question may also be: What happens if I don't define a destructor what so ever? Al:confused:

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          In a pure managed class it will be GC'd as normal... The destructor is just there to free up any non-managed resources during GC. If you do have unmanaged resources though you are encouraged to implement IDisposable so that they can be returned ASAP. I have no idea what happens when you mix managed/unmanaged together though :confused: I assume you could treat it like another system resource, implementing IDisposable and calling Dispose from the destructor/finalize methods. James Simplicity Rules!

          A 1 Reply Last reply
          0
          • J James T Johnson

            In a pure managed class it will be GC'd as normal... The destructor is just there to free up any non-managed resources during GC. If you do have unmanaged resources though you are encouraged to implement IDisposable so that they can be returned ASAP. I have no idea what happens when you mix managed/unmanaged together though :confused: I assume you could treat it like another system resource, implementing IDisposable and calling Dispose from the destructor/finalize methods. James Simplicity Rules!

            A Offline
            A Offline
            Albert Pascual
            wrote on last edited by
            #5

            So, if I don't have any unmanaged code I could just delete the destructor! Great! Thanks James! Al

            N 1 Reply Last reply
            0
            • A Albert Pascual

              So, if I don't have any unmanaged code I could just delete the destructor! Great! Thanks James! Al

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              Albert Pascual wrote: So, if I don't have any unmanaged code I could just delete the destructor! Great! That's what it's called Managed C++. Part of the "managed" is about garbage collection. Nish


              Check out last week's Code Project posting stats presentation from :- http://www.busterboy.org/codeproject/ Feel free to make your comments.

              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