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. Singleton/static member question...

Singleton/static member question...

Scheduled Pinned Locked Moved C#
questiondotnet
2 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.
  • R Offline
    R Offline
    Ryan Cromwell
    wrote on last edited by
    #1

    Can someone explain to me the lifetime of a static member variable? That is, in a singleton, one has a static member variable of the single instance and a static member function which returns a reference to that instance. How is it that, 1) the static member variable is maintained, 2) the static member variable is destroyed (GC in the CLR, but what about unmanaged languages)?

    L 1 Reply Last reply
    0
    • R Ryan Cromwell

      Can someone explain to me the lifetime of a static member variable? That is, in a singleton, one has a static member variable of the single instance and a static member function which returns a reference to that instance. How is it that, 1) the static member variable is maintained, 2) the static member variable is destroyed (GC in the CLR, but what about unmanaged languages)?

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

      You will need to count the references created to it, and if none is needed anymore, the unmanaged resources can be released. By design a static member will instantiate whenever it is first accessed and will last the lifetime of the appdomain. There is no GC on those objects AFAIK.

      leppie::AllocCPArticle(Generic DFA State Machine for .NET);

      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