Вопрос

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?

Это было полезно?

Решение

1) As you have already found out the size of the instance of A does not include the size of the referenced objects. However, if you want to find out the size use the !objsize command. Keep in mind that if multiple objects reference the same other objects the size of these will be included multiple times.

2) The object referenced by a1 does not get allocated on the LOH. The object itself is less than 85000 bytes, so it is allocated on the regular heap. Use the !gcwhere command to list what part of the heap a given object is in.

3) It doesn't matter if the b1 reference points to a large object. The size of any instance of A will only be three references plus some additional overhead (a reference to the type object and a syncblock). I.e. the size will be very far from the LOH limit.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top