Andy
Andy

Reputation: 2318

Can i find out how much memory a Collection uses?

I have a Collection of lineEntitys. I would like to see how big the size of it is in memory.

Is there a way of finding out similar to using sizeof(int) to accomplish this?

Upvotes: 1

Views: 638

Answers (1)

Mitch Wheat
Mitch Wheat

Reputation: 300559

CLR Profiler for .NET Framework 4:

The CLR Profiler includes a number of very useful views of the allocation profile, including a histogram of allocated types, allocation and call graphs, a time line showing GCs of various generations and the resulting state of the managed heap after those collections, and a call tree showing per-method allocations and assembly loads.

Another option is to wrap your allocation in two calls to GC.GetTotalMemory():

        long memoryUsed = GC.GetTotalMemory(false);

Also, Inspect and Optimize Your Program's Memory Usage with the .NET Profiler API

Upvotes: 5

Related Questions