c# - 我可以找出一个集合使用了多少内存吗?

标签 c# visual-studio-2010 memory

我有一个 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/

相关文章:

visual-studio - 如何完全禁用代码契约(Contract)?

visual-studio-2010 - Visual Studio 2010 加载符号时间过长,无法删除符号文件位置

mongodb - mongo 不遵守 Docker 内存限制

java - 算法简单但内存不足

c# - QuickGraph Metro 风格应用程序支持

c# - 空间坐标的 3D 数组

visual-studio-2010 - 目标框架, ".NET Framework ... Client Profile"是什么意思?

c - 获取 C 程序修改的所有内存位置的日志

c# - 正确的语法;没有结果

c# - 如何制作整个 C# 应用程序 "unsafe"?