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. Other Discussions
  3. The Weird and The Wonderful
  4. reassigning static variable

reassigning static variable

Scheduled Pinned Locked Moved The Weird and The Wonderful
adobeperformancequestion
6 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.
  • E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #1

    static object s_obj = new object();

    then in some function,

    void func()
    {
    object obj = new object();
    s_obj = obj;
    }

    Honestly, I have never seen such a code before. X| When someone does this, what actually happens to the memory, statically allocated to s_obj, initially? It's left hanging on the air without any reference ?

    Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

    K 1 Reply Last reply
    0
    • E Eytukan

      static object s_obj = new object();

      then in some function,

      void func()
      {
      object obj = new object();
      s_obj = obj;
      }

      Honestly, I have never seen such a code before. X| When someone does this, what actually happens to the memory, statically allocated to s_obj, initially? It's left hanging on the air without any reference ?

      Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      Depending on garbage collection the memory should be released, because the ref counter of the original object is set to zero in the func() assigment.:~

      Press F1 for help or google it. Greetings from Germany

      E Richard DeemingR 2 Replies Last reply
      0
      • K KarstenK

        Depending on garbage collection the memory should be released, because the ref counter of the original object is set to zero in the func() assigment.:~

        Press F1 for help or google it. Greetings from Germany

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #3

        Thanks, But does this apply even to Static Variables?

        Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

        L 1 Reply Last reply
        0
        • E Eytukan

          Thanks, But does this apply even to Static Variables?

          Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes; the object ("new object") is not static; the pointer-variable holding that object is. Once another object is assigned to it, the other object is no longer referenced.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          E 1 Reply Last reply
          0
          • L Lost User

            Yes; the object ("new object") is not static; the pointer-variable holding that object is. Once another object is assigned to it, the other object is no longer referenced.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            :thumbsup: :)

            Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy Falcon.

            1 Reply Last reply
            0
            • K KarstenK

              Depending on garbage collection the memory should be released, because the ref counter of the original object is set to zero in the func() assigment.:~

              Press F1 for help or google it. Greetings from Germany

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              KarstenK wrote:

              the ref counter of the original object is set to zero

              If it's .NET, there's no ref counter. Instead, the GC will detect that the object is no longer reachable. That way, circular references won't leak memory. :)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              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