简体   繁体   English

短时间后,在vb.net应用程序的私有KB中分配了超过1000 MB的空间

[英]Over 1000 MB allocated in private KB in vb.net application after little time

I have a vb.net application that uses SQL connections and SQL objects (like datatables and commands). 我有一个使用SQL连接和SQL对象(如数据表和命令)的vb.net应用程序。 Now I planned to test memory issues and see if there is something wrong about memory.. 现在,我计划测试内存问题,看看内存是否有问题。

I have inserted timer and made it show specific form in my application every 1 second and close it.. 我已插入计时器,并使其每隔1秒在我的应用程序中显示特定的形式,然后将其关闭。

This form contains very very simple form load code, just about populate combo boxes from SQL Server (standalone comboboxes and in datagrids). 此表单包含非常简单的表单加载代码,仅用于填充SQL Server中的组合框(独立组合框和数据网格)。

Now, in resources monitor in memory tab and especially in private KB field, the memory is growing up and never releases, it reached 1 GB and more ! 现在,在“内存”选项卡中的资源监控器中,尤其是在私有KB字段中,内存正在增长并且从未释放,它已达到1 GB或更多!

Why that happens often ? 为什么这种情况经常发生?

Notes: 笔记:

  • Vb.net Vb.net
  • VS 2012 VS 2012
  • SQL Server 2008 SQL Server 2008
  • Using DevExpress Components 使用DevExpress组件
  • Calling Dispose() after using Connections. 使用连接后调用Dispose()

I watched the GDI Objects memory, it releases every form close so i think it's not GDI memory problem. 我看着GDI对象的内存,它关闭了所有窗体,所以我认为这不是GDI内存的问题。

timer working time is less than 5 Min. 计时器的工作时间少于5分钟。

Any Ideas ? 有任何想法吗 ?

I would suggest, for safety, you consider using the "Using" keyword. 为了安全起见,我建议您考虑使用“使用”关键字。 This will ensure as soon as your connections fall out of scope they are disposed. 这将确保您的连接一旦超出范围就将被丢弃。 Any object that implements IDisposable can be used with a Using Statement. 任何实现IDisposable的对象都可以与Using语句一起使用。

Using conn as new SQLConnection(connString)
    'Do some stuff with your SQL connection
End Using

This is just good practice and means you don't have to use Try... Finally to ensure closed connections. 这只是个好习惯,这意味着您不必使用Try ... Final来确保关闭的连接。

You will also need to look at other possible causes of your memory leak. 您还需要查看导致内存泄漏的其他可能原因。 May need to consider the scope of how you show the form, also. 可能还需要考虑如何显示表单的范围。 Try making the code that opens your form dispose the form, too; 尝试使打开表单的代码也配置该表单;

Using frmFoo as new frmMain
   frmFoo.Show()
End Using

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM