[英]DWM Leaks Memory When No Monitor Connected Windows 8
Simply, if no monitor connected and you are doing some "windows" operation on windows 8 embedded, dwm.exe starts allocating memory and never stops . 简而言之, 如果未连接任何监视器,并且您正在嵌入式Windows 8上执行某些“ Windows”操作,则dwm.exe将开始分配内存,并且永不停止 。
to regenerate and show you all the problem, i have written an application which is doing "Create a new Form and show it, if there is one created close it first" 为了重新生成并向您显示所有问题,我编写了一个应用程序,该应用程序正在执行“创建新表单并显示它,如果创建了一个新表单,请先关闭它”。
public partial class PopupWindows : Form
{
private Timer _t;
private Form _form;
public PopupWindows()
{
InitializeComponent();
this.Size = new Size(500, 500);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_t = new Timer();
_t.Tick += (o, ea) =>
{
_form?.Close();
(_form = new Form() { Size = this.Size }).Show();
};
_t.Interval = 1000;
_t.Enabled = true;
}
}
if you run this application and plug out the monitor, dwm start allocating pages here is the output from pslist -m when the monitor connected 如果运行此应用程序并插入监视器,则dwm开始分配页,这是在监视器连接后 pslist -m的输出
Name Pid VM WS Priv Priv Pk Faults NonP Page
dwm 840 123528 14400 11264 13044 55125 7 212
after some time but still the monitor connected 一段时间后,但显示器仍然连接
dwm 840 117144 15808 12732 13044 94051 7 200
disconnecting monitor and dwm.exe start allocating 断开监视器和dwm.exe的连接开始分配
dwm 840 214660 14444 12664 13044 137409 13 400
below is the output where you can see allocation dwm.exe doing 下面是输出,您可以在其中看到分配dwm.exe的操作
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 251956 14460 12740 13044 137413 16 477
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 251956 14460 12740 13044 137413 16 477
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 251956 14460 12740 13044 137413 16 477
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 252964 14460 12740 13044 137413 16 479
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 252964 14460 12740 13044 137413 16 479
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 253972 14460 12744 13044 137413 16 481
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 253972 14460 12744 13044 137413 16 481
C:\PSTools>pslist.exe -m|findstr "dwm"
dwm 840 254980 14460 12744 13044 137413 16 483
and this strange act dwm doing never stops till you connect a monitor or doing vnc connection to the computer. 直到您将监视器连接到计算机或进行vnc连接之后,dwm的这种奇怪行为才会停止 。
after some time on operation without monitor , every os component starts to complain about memory and a blue screen of death occurs at the end . 在没有监视器的情况下运行一段时间后,每个os组件都开始抱怨内存,最后出现蓝屏死机 。
let me show you the last one 让我告诉你最后一个
dwm 840 807516 15624 14216 17240 147413 50 1603
here is the output showing how many minutes my popupwindows.exe running 这是显示我的popupwindows.exe运行多少分钟的输出
Name Pid Pri Thd Hnd Priv CPU Time Elapsed Time
PopupWindows 2052 6 4 138 9468 0:00:00.140 0:23:07.332
as you can see, after about 20 minutes without having a monitor on the device, dwm.exe using 807516 bytes VM and 1603 pages. 如您所见,大约20分钟后在设备上没有显示器的情况下,dwm.exe使用807516字节的VM和1603页。
Acting like what vnc doing (copying whole screen bitmap to application memory regularly) solved the dwm's allocation problem (which i think dwm caches its outputs but no one come and ask for the changes so it keeps all of them in the memory and never cleans). 像vnc一样(定期将整个屏幕位图复制到应用程序内存中)解决了dwm的分配问题(我认为dwm会缓存其输出,但是没有人来请求更改,因此将所有这些都保存在内存中并且从不清理) 。
below is the application which starts hidden and regularly copying screen image into app memory 下面是开始隐藏并定期将屏幕图像复制到应用程序内存中的应用程序
public partial class HiddenForm : Form
{
IntPtr _this;
private System.Windows.Forms.Timer _timer;
private Bitmap _bmp = null;
public HiddenForm()
{
this.Visible = false;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
this.HandleCreated += (s, e) => _this = this.Handle;
this.Load += (s, e) => this.Size = new Size(0, 0);
CreateHandle();
CreateControl();
_timer = new System.Windows.Forms.Timer();
_timer.Tick += _timer_Tick;
_timer.Interval = 2000;
_timer.Start();
}
private void _timer_Tick(object sender, EventArgs e)
{
if (Screen.PrimaryScreen == null)
return;
if (_bmp == null)
{
using (Graphics g = CreateGraphics())
{
_bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g);
}
}
using (Graphics grp = Graphics.FromImage(_bmp))
{
grp.CopyFromScreen(0, 0, 0, 0, _bmp.Size);
}
}
}
here is the output after starting my app 这是启动我的应用程序后的输出
Name Pid VM WS Priv Priv Pk Faults NonP Page
dwm 832 117876 20188 19624 35004 184497 7 185
killing my app with pskill waiting a while 用pskill杀死我的应用程序
dwm 832 182388 20264 19852 35004 421343 11 317
it starts increasing to re check our app i started it again by typing 它开始增加以重新检查我们的应用程序,我通过键入再次启动它
C:\HiddenForm.exe
and dwm.exe memory allocation magically downed. 和dwm.exe的内存分配神奇地减少了。
dwm 832 126384 27900 27364 35144 556729 7 187
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.