memory management for a value and reference type

I have searched about the subject of reference type vs value type in C# and data allocation in stack and heap.

From these sources , stackoverflow question and this article, I make this conclusion :

  • The value of reference type is stored on the heap, and the adress of this value is stored on the stack
  • A value type is stored on the stack
  • Local variables of running function are stored in the stack
  • Global variables are stored on the heap
  • I have few questions :

  • If I had a global variable and it is a value type. where it will be stored?
  • If I had a local reference type variable. where it will be stored?
  • Why it is recommended to write this :

    public class OurClass()
    {
       public ClassA objA;  
       public OurClass()
       {
        objA = new ClassA();
       }
    }
    
  • Instead of writing

     public class OurClass()
        {
           public ClassA objA = new ClassA(); 
           public OurClass()
           {
    
           }
        }
    

    Did it have relation with allocation performance?

    Thanks,

    链接地址: http://www.djcxy.com/p/82602.html

    上一篇: JVM如何为静态字符串变量分配内存?

    下一篇: 内存管理的值和引用类型