When creating 2 objects of the same type, will the handle from the stack memory point to the same object in the heap or will it point to 2 separate objects. For clarity here is the specific question...
class Q2 {
private static int num = 0;
private String prefix;
public Q2 (String p)
{ prefix = p; }
public String Msg (String str) {
String n;
num++;
n = num.ToString();
return n + " - " + prefix + str;
}
}
Using an appropriate diagram, describe the state of memory after all of the following statements have been executed.
Q2 var1, var2;
var1 = new Q2("Question 2");
var2 = new Q2 ("Another view");
Here are the answers I cannot decide between:
1 object:
2 objects:
The heap is an area of dynamically-allocated memory that is managed automatically by the operating system or the memory manager library. Memory on the heap is allocated, deallocated, and resized regularly during program execution, and this can lead to a problem called fragmentation.
Memory allocation NET framework that allocates and releases memory for your . NET applications. When a new process is started, the runtime reserves a region of address space for the process called the managed heap. Objects are allocated in the heap contiguously one after another.
NET Framework that allocates and releases memory for your . NET applications. The Common Language Runtime (CLR) manages allocation and deallocation of a managed object in memory. C# programmers never do this directly, there is no delete keyword in the C# language.
Heaps, Heaps and more HeapsNet stores most of the variables you will create (except for the value types) on a data-structure called the heap. This lives in the process address space and grows as more and more variables are needed and allocated by the application. The key is the 'growing when needed'.
To help clarify the discussion on the heaps here, there are about 8 different heaps that the CLR uses:
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With