Search Unity

static methods on the heap

Discussion in 'Scripting' started by Wasiim, Jul 29, 2015.

  1. Wasiim

    Wasiim

    Joined:
    May 2, 2015
    Posts:
    228
    I recently (like... just now) got this idea that maybe static methods and variables are completely isolated on the heap and have no connections to the stack. Is this true?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    well, methods aren't on the heap first and foremost. They're in program memory.

    Methods ACCESS the heap. Static or not.

    static variables do exist in a special part of the heap reserved for static values. But that doesn't mean they're completely isolated. If that static variable is a value type (a struct or primitive like int), when you use it, the value is copied to the stack for use.