i like to know in details and want to visualize how memory is allocated in dotnet program. sorry because i will be asking few question. so please answer point wise in detail.
1) suppose i have class called employee which has data member called empNo, Name and Salary. so i like to know when we will create object of employee then how memory will be allocated ?
2) where memory will be allocated for employee object? in heap or stack?
3) why memory is allocated in heap for object and local variable in stack?
4) i hear some time memory is allocated in heap for local variable but when?
5) where actual data is stored like employee name or salary in heap or stack? if in stack why? why not in heap?
6) i heard that memory is allocated for static class in high frequency heap........what is high frequency heap and how it is different than normal heap?
VulpesPosted Mar 1, 2015, 4:43 PM
A reference is simply a pointer which is tracked by the garbage collector. If memory is compacted following a collection, then the address of an object (and hence any references to it) may change.
Posted Mar 1, 2015, 12:20 PM
you said : Suppose empNo is an int, Name is a string and Salary is a double. Sufficient memory will be allocated on the heap to accomodate these 3 fields plus overhead of 8 bytes (32 bit system) or 16 bytes (64 bit system).
empno & salary is value type then why u r saying value of those fields will be stored in heap? i guess they should be stored in stack because they are fixed size.
u said : Local variables must of necessity be stored on the stack
which local variable u r talking about? variable declared inside in function? if yes then we can declare ref type variable inside function then those variable should store on heap i guess ?
make all ur points more clear with sample code. thanks
VulpesPosted Feb 26, 2015, 12:30 PM
Vithal WadjePosted Feb 26, 2015, 10:58 AM
http://www.c-sharpcorner.com/UploadFile/tkagarwal/MemoryManagementInNet11232005064832AM/MemoryManagementInNet.aspx