空白上下的WinForms应用程序内存过度消耗 [英] Excessive Memory Consumption in blank-ish WinForms application

查看:145
本文介绍了空白上下的WinForms应用程序内存过度消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的Windows窗体应用程序消耗越来越多的内存时,它是一个空白的应用程序,甚至没有正在使用的用户(我)?

Why is my Windows Forms application consuming more and more memory when it's a blank app and not even being used by the user (me)?

您可能能够重现以下步骤操作:

You may be able to reproduce with these steps:

  1. 在打开Visual Studio 2013旗舰版
  2. 新建项目> C#> Windows窗体应用程序> .NET框架4.5

添加图片框 Form1中工具箱面板

这是我发疯了明显的原因。我的应用程序在约LT开始了,1MB,并在几分钟的事,它是由〜10MB。给它一个几分钟,它的再次到〜40MB。而且它不会停在那里。事实上,我离开它运行在晚上,当我醒来的时候,电脑反应迟钝。

This is driving me nuts for the obvious reason. My app starts off at about <1MB and within a matter of a few minutes, it's up to ~10MB. Give it a few more minutes and it's up again to ~40MB. And it doesn't stop there. In fact, I left it running over night and when I woke up, the PC was unresponsive.

推荐答案

GC未收集未使用的内存,因为它是非常小的。

The GC is not collecting unused memory, since it's is very small.

您可以尝试迫使GC收集(不是一个好的做法,只是为了测试)

You can try forcing the GC collect (not a good practice, just for testing)

public Form1()
    {
        InitializeComponent();
        _timer.Interval = 10000;
        _timer.Tick += _timer_Tick;
        _timer.Start();
    }

    void _timer_Tick(object sender, EventArgs e)
    {
        GC.Collect();
    }

在此之后,内存保持在3.2 MB的我的电脑:)

After this the memory stays at 3.2 MB at my PC :)

这篇关于空白上下的WinForms应用程序内存过度消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆