我有一个 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
关于c# - 我可以找出一个集合使用了多少内存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5431945/