Windows Phone 监视内存使用情况

本文介绍如何在Windows Phone上监测应用的内存使用情况,包括通过Microsoft.Phone.Info.DeviceExtendedProperties类获取设备总内存、当前应用内存使用量及峰值等信息,并提供了一个简化方法通过引入特定DLL实现内存监控。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 在调试Windows Phone程序的时候,我们通常需要知道当前程序占用的内存是多少,有没有发生内存泄露。

 在之前的Windows Phone 7 Tips (5) 中有提到EnableFrameRateCounter 是监视程序运行时的帧速率,具体的用法如下

// Show graphics profiling information while debugging.
if (System.Diagnostics.Debugger.IsAttached)
{
  // Display the current frame rate counters.
  Application.Current.Host.Settings.EnableFrameRateCounter = true;

以下是右侧工具条的具体解释

 

 这里并没有我们想要看的内存的使用情况,如何去做呢。在Windows Phone 中有这么一个类 Microsoft.Phone.Info.DeviceExtendedProperties  提供内存的使用情况,具体的属性指如下:

属性值返回值描述
DeviceTotalMemorylong integer设备总内存(单位字节)
ApplicationCurrentMemoryUsagelong integer当前应用程序内存使用量(单位字节)
ApplicationPeakMemoryUsagelong integer当前应用程序最高使用量(单位字节)

 可能你需要写如下的代码来查看这些数据

 

当然还有更简单的方法,就是引入一个dll(Dll下载),然后写几段代码就完事了。 

 dnp.Counter.EnableMemoryCounter = true;

 默认是2秒刷新一次,当然你可以自己设定刷新间隔

 dnp.Counter.SetTimerInterval(1);

 


参考

http://blogs.msdn.com/b/mikeormond/archive/2010/12/16/monitoring-memory-usage-on-windows-phone-7.aspx 

http://dotnetprofessional.com/blog/post/2010/09/27/Debug-Memory-Counter-for-Windows-Phone-7.aspx 

转载于:https://www.cnblogs.com/alexis/archive/2011/05/02/2034250.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值