Junior — Middle
Kus tavaliselt paiknevad viidetüübi objektid mälus?
sobes.tech AI
Vastus AI-lt
In C#, reference type objects are typically placed in the managed heap. This is a memory area allocated for storing objects during program execution.
When a reference type object (e.g., a class) is created, memory for it is allocated on the heap, and the variable holds a reference (pointer) to that object. Memory management on the heap is handled by the Garbage Collector, which automatically frees memory when objects become inaccessible.
Example:
class Person {
public string Name;
}
Person p = new Person(); // object is created on the heap
Here, p is a variable that holds a reference to the Person object, which is located on the heap.