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提供内存的使用情况,具体的属性指如下:
属性值
返回值
描述
DeviceTotalMemory
long integer
设备总内存(单位字节)
ApplicationCurrentMemoryUsage
long integer
当前应用程序内存使用量(单位字节)
ApplicationPeakMemoryUsage
long 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
页:
[1]