Say I have following class:
Class A
{
B b;
C c;
D d;
}
First, I allocate:
var b1 = new B();
var c1 = new C();
var d1 = new D();
each of b1, c1, d1
is less than 85K, so they get allocated on the small object heap.
Then I do:
var a1 = new A { b = b1, c = c1, d = d1 };
Question1: When I do !DumpHeap -stat
does the mem usage of A
include memory occupied by its member variables? If not, what does it actually include?
EDIT: found answer to this question in this post: http://blogs.msdn.com/b/tess/archive/2005/11/25/dumpheap-stat-explained-debugging-net-leaks.aspx. It makes sense that mem usage of A
does NOT include memory occupied by b1, c1, d1
. It includes the memory needed to store the b1, c1, d1
references themselves.
Question2: Does a1
get allocated on the large object heap (assume size of b1 + c1 + d1
> 85K)? Why? The references b1, c1, d1
point to objects on small object heap. Then why would a1
sit on the LOH?
Question3: Lets flip it around. Say size of b1
is more than 85K, so its allocated on the LOH. But to store references to b1, c1, d1
we only need a few bytes. Am I correct in believing that a1
will be allocated on the small object heap?