内存分析工具和方法
我正在尝试分析 Windows Phone 7 应用程序的内存使用情况。在浸泡测试后,查询 ApplicationPeakMemoryUsage
属性会产生约 90Mb 的值。 System.GC.GetTotalMemory(true)
此时返回~11Mb,因此余额必须是非托管内存。该应用程序没有显式分配任何非托管内存,因此我假设平衡是 GPU 资源、音频和应用程序二进制文件本身。
通过围绕对 ContentManager.Load()
的调用和 GPU 资源分配(new RenderTarget2D()
等)。使用类似的代码,
System.GC.Collect();
unused = System.GC.GetTotalMemory(true);
GC.WaitForPendingFinalizers();
long mem = ((long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage"));
.
. // perform loads/allocations
.
mem = ((long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage")) - mem;
我可以获得渲染缓冲区、纹理/音频资源等使用的内存的近似数字。我的应用程序中的这些总计约为 45-50Mb。 ApplicationCurrentMemoryUsage
在初始化开始时立即产生略低于 10Mb 的空间。再减去 11Mb 托管堆(这部分是重复计算的!),这会留下约 20Mb 的空间。
Mango 内存分析器跟踪总数,但仅细分托管堆的分配。除了 GPU 资源、音频和应用程序二进制文件本身之外,还有什么可能使用大量非托管内存?有没有比我正在做的更明智的跟踪记忆的工具或方法?
I'm attempting to analyze memory usage of our Windows Phone 7 app. Querying the ApplicationPeakMemoryUsage
property yields a value of ~90Mb following a soak test. System.GC.GetTotalMemory(true)
returns ~11Mb at this time, so the balance must be unmanaged memory. The app does not explicitly allocate any unmanaged memory, so I assume the balance is GPU assets, audio and the app binary itself.
By surrounding calls to ContentManager.Load()
and GPU resource allocations (new RenderTarget2D()
, etc). with code similar to
System.GC.Collect();
unused = System.GC.GetTotalMemory(true);
GC.WaitForPendingFinalizers();
long mem = ((long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage"));
.
. // perform loads/allocations
.
mem = ((long)Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("ApplicationCurrentMemoryUsage")) - mem;
I am able to obtain approximate figures for memory used by render buffers, texture/audio resources etc. These total ~45-50Mb across my app. ApplicationCurrentMemoryUsage
yields just under 10Mb immediately at the start of initialization. Subtracting the 11Mb managed heap as well (which is partly double-counting!), this leaves ~20Mb unaccounted for.
The Mango memory profiler tracks the totals but only breaks down allocations for the managed heap. What else might be using large quantities of unmanaged memory other than GPU resources, audio and the app binary itself? Are there any more sensible tools or methods for tracking memory than what I am doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下载的文件(包括来自网络的图像)可能会占用大量内存。如果您正在使用它们,请务必再次正确释放内存(请参阅http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx)。
Downloaded files (including images from the web) can use lots of memory. If you're using them be sure to free up the memory again properly (see http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx).
您使用的是 WebBrowser 控件吗?
它有一些缺陷,在某些情况下可能会导致巨大的(和增量的)内存泄漏,特别是当页面包含许多媒体或复杂的脚本时,或者当其页面在不幸的时机重新加载/更改时。
Are you using a WebBrowser control?
It has some flaws and can cause huge (and incremental) memory leaks in some scenarios, especially if the page contains many media or complicated scripts, or when its page is reloaded/changed with unlucky timing..