数据集copy()内存泄漏 [英] Dataset copy() memory leak

查看:135
本文介绍了数据集copy()内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个需要经常备份数据集并如果用户决定取消操作的应用程序,则应恢复到该备份的应用程序.
在该类的顶部创建了一个全局数据集:

Hi
I have an application that needs to frequently backup a dataset and revert to that backup if the users decides to cancel an action.
There is a global dataset created at the top of the class:

DataSet database = null;



每次打开表单时,主数据集都会复制到创建的变量中:



Every time a form is opened the main dataset is copied into the created variable:

database = AppModel.Instance.Data.Data.Copy();


问题在于,每次打开表单时,内存都会增加很多,并且永远不会释放.
我曾尝试在使用数据库变量后将其释放,但内存仍然很高-这使我相信DataSet.Copy()方法每次都会分配给新内存.

任何释放内存的建议将不胜感激.
问候,
Jason


The problem is that every time the form is opened the memory increases by quite a lot and is never released.
I''ve tried disposing the database variable after it''s been used but the memory still remains high - This has left me to believe that the DataSet.Copy() method allocates to new memory every time.

Any suggestions to free up the memory would be greatly appreciated.
Regards,
Jason

推荐答案

我不明白.让我看看你想做什么.当用户打开新表单时,您将复制数据集,以便在用户改变主意的情况下可以得到一个副本.对.

我要做的是,而不是一遍又一遍地复制数据,而是利用内置功能在用户下定决心时接受或拒绝更改

查看 DataSet.RejectChanges [ DataSet.AcceptChanges [
I don''t get it. Let me see what you trying to do. When a user opens a new form, you copy the dataset so that you can have a copy in a case when and if the user changes his mind? right.

What I would do is that, instead of copying that chuck of data over and over again, utilize the build-in functionality to accept or to reject the changes as the user makes his mind

Look at DataSet.RejectChanges[^]

DataSet.AcceptChanges[^]




如果您使用C#和.net,那么您将无法强制垃圾回收器,因此正在处理备份数据集正在等待....您的内存分配也是如此.

现在,如果您必须经常备份,我建议您使用一个嵌入式数据库,并根据自己的意愿创建一个备份例程,这样就不会使用过多的内存.
而且,如果您对备份例程进行微调以使用dataset.GetChanges(),则事务处理将更快..

而且,如果您不想拥有所有预制的嵌入式数据库,为什么不添加它,就可以立即创建方案定义".

希望对您有所帮助
grtz
Hi there,

If your working with C# and .net then you cannot force the garbage collector and thus disposing of the back-up dataset is pending....and so is your memory allocation.

Now if you have to backup frequently I suggest an embedded database and creating a backup routine according to your wishes... and thus not using more memory than needed.

And if you fine tune your backup routine to working with dataset.GetChanges(), the transaction wil be even faster..

And if you don''t wanna have an embedded database all pre-made, why not add, create "scheme deffinitions" on the fly.

I hope this helped
grtz


好吧,您可以请求垃圾收集器通过
运行垃圾收集过程
GC.Collect();
GC.WaitForPendingFinalizers();

由于GC本身的算法和流程,这不能保证立即清除内存,因此不建议这样做,因为垃圾收集是一个成本很高的过程,因为它必须检查标记为已处置的所有事物并在清理之后它会按顺序重新放置所有内存对象.

这是链接:
http://msdn.microsoft.com/en-us/library/system.gc. waitforpendingfinalizers.aspx [^ ]

谢谢,
Hemant
Well you can request the Garbage collector to run garbage collection process by

GC.Collect();
GC.WaitForPendingFinalizers();

This doesn''t guarentee the memory to be cleaned up immediately because of GC''s own algo and flow plus this is not recommended because and garbage collection is a costly process as it has to check every thing marked as disposed and after cleaning up it re-position all in-memory objects sequally.

here is the link:
http://msdn.microsoft.com/en-us/library/system.gc.waitforpendingfinalizers.aspx[^]

Thanks,
Hemant


这篇关于数据集copy()内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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