我有一个 lineEntity 集合。我想看看它在内存中的大小。
有没有一种类似于使用 sizeof(int) 来完成此操作的方法?
请您参考如下方法:
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.
另一种选择是将您的分配包裹在对 GC.GetTotalMemory(): 的两次调用中
long memoryUsed = GC.GetTotalMemory(false);
此外,Inspect and Optimize Your Program's Memory Usage with the .NET Profiler API
