您的位置:首页 > 编程语言

Windows Phone 监视内存使用情况 推荐

2011-05-02 11:09 302 查看
在调试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

附件:http://down.51cto.com/data/2358250
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息