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. Static destructor?

Static destructor?

Scheduled Pinned Locked Moved C#
questiondiscussionworkspace
3 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.
  • C Offline
    C Offline
    CBoland
    wrote on last edited by
    #1

    My class contains an unmanaged system object member (a user profile handle) that is initialized in the static constructor. Conversely, I need to free the object when the class (not object instances) is destroyed, but I've never heard of a static destructor. Perhaps I could use Environment.HasShutdownStarted in the finalizer, but all instances could have already been gc'd when the AppDomain unloads and the code wouldn't run. Perhaps I could use the AppDomain.Unload event to run my code. Any thoughts?

    L 1 Reply Last reply
    0
    • C CBoland

      My class contains an unmanaged system object member (a user profile handle) that is initialized in the static constructor. Conversely, I need to free the object when the class (not object instances) is destroyed, but I've never heard of a static destructor. Perhaps I could use Environment.HasShutdownStarted in the finalizer, but all instances could have already been gc'd when the AppDomain unloads and the code wouldn't run. Perhaps I could use the AppDomain.Unload event to run my code. Any thoughts?

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

      CBoland wrote: but I've never heard of a static destructor. They are allowable by the CLR, but I suggest using a Singleton pattern instead of static if it involves any resources. :) leppie::AllocCPArticle("Zee blog");
      Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

      C 1 Reply Last reply
      0
      • L leppie

        CBoland wrote: but I've never heard of a static destructor. They are allowable by the CLR, but I suggest using a Singleton pattern instead of static if it involves any resources. :) leppie::AllocCPArticle("Zee blog");
        Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

        C Offline
        C Offline
        CBoland
        wrote on last edited by
        #3

        Good call. Thanks for the reply.

        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