Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
where static variables are stored whether heap or stack .why they are globally available entire the application.how garbage collector acts on it.please give me clear explanation i am confused about static variables.
Posted

1 solution

Every static variable is stored on the heap, regardless of the type: value types and reference types are stored there. Since the lifetime of a static variable is the duration of the application, the garbage collector never disposes them during normal operation.

If they weren't then they would have to be stack based, and then they would not be the same variable in different threads.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900