Question about memory allocation?

public static void Main()
        {
            Test t1 = new Test();
}

when t1 (reference variable) gets memory, at compile time or at runtime.
I think it should be a work time. But when I set a breakpoint in the Main Method and Put a Watch for t1, it was null. So this means that t1 was in memory.

Please correct me if I am wrong.

Edit: I heard that static member variables are assigned at compile time.

+5
source share
8 answers

t1 Main - ( "new Test()" ) - t1 null.

+3

( ).

t1 (.. null) , , , . Main , , , .

.. Test1 t1 = new Test1();, , .

+5
Test t1;

(, 4 , , .NET framework), ( ), Main .

t1 = new Test();

Test, t1 . , t1 Test().

: , - , , . , - . , , , (, , , ).

class Test2
{
   public static Test f1 = new Test();
}

Test, , Test2.

+2

"Main" ( new Test()). , .

Test t1 ( ), , ( , "Main" ).

, , .

, ( ).

" " , JIT, , .

+2

, , t1 . new Test() t1 Test .

.

+1

. :

  • , "" -.
  • , , .
  • , , .
  • , .
  • , .

, ...

+1

, .

:

Main()
{
  Test t1;
  t1 = new Test();
}

:

  • {, Test t1, t1 = new Test() }
  • {execute - t1 - Why??

    . . - t1 . ?

  • Test t1.

    - t1 /.

    ? , RUN/RAN/Executed. , .

    - ? , Reference/Pointer/Object. , null. , ?

  • .

    null - - , , /.

  • :

    , .

    / new Test() , t1? – !

    , , , .

    , Test t1=null, , , - , Test() , .

    Main ( ) - - ( ), - / .

@ Static stuff: I'm trying to find out about static classes / variables and methods.

@People: Correct me if I am wrong in some place.

+1
source

run the application in debug mode, F5 is basically a keyboard shortcut in visual studio. Place a breakpoint on this statement. Use F10 to go to the next statement. Moment debugger steps the next statement you will see the object being created.

0
source

All Articles