Windows Phone 监视内存使用情况

在调试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

 

 

源码下载

本文来Alexis的博客,原文地址:http://www.cnblogs.com/alexis/archive/2011/05/02/2034250.html

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值