用户控制未处置 [英] User Control Not Disposing

查看:53
本文介绍了用户控制未处置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个包含多个属性和事件的用户控件。这个用户控件充满了SQL数据库中一个条目的信息。



问题列在底部。

首先,这里是一些信息。



- 不确定是否相关但有怀疑 -

控件中的一些变量被声明为WithEvents。这些变量属于类型类型,我为了解决一些循环引用问题而制作了b
。从本质上讲,它允许我的控制

将事件提升到主应用程序,告知它需要做什么。该应用程序在收到活动并参考所有项目后,可以执行控件所需的任何操作。



如何工作..

这是我的类允许应用程序监视所有现有用户控件的需求。

Hi all,

I have a user control with several properties and events. This user control is filled with information of one entry in an SQL database.

The problem is listed at the bottom.
First, here is some information.

-- Not sure if relevant but have a suspicion --
some Variables in the control are declared as WithEvents. Those variables are of a class type that
I made in order to get around some circular reference issues. Essentially, it allows my control
to raise an event to the main application, informing it of what needs to be done. The application, having received the event and having references to all projects, can then perform whatever action is required by the control.

How this works..
Here is my class for allowing application to monitor the needs of all existing user controls.

Class ControlEvents

Public Shared Event ViewUser(Sender as MyControl)

Sub View(Sender as MyControl)
  RaiseEvent ViewUser(Sender)
End Sub

end Class







这是用户控件用一个子视图翼一个用户




Here is the user control with a sub for viewing a user

Class MyControl
  Private WithEvents Subcription_ControlEvents As New ControlEvents

  Sub ViewUser()
    'Raise the event in the ControlEvents Class for the application to see
     Subcription_ControlEvents.View(Me)
  End Sub
End Class





最后,应用程序模块正在监视Control事件并响应他们





And finally, the applications Module watching for Control events and responding to them

Module UserControl_EventMonitor
   Private WithEvents Subcription_ControlEvents As New ControlEvents
   
   Private Sub MyControlClass_ViewUser(Sender as MyControl) Handles Subcription_ControlEvents.View
   'This is where I do Stuff to view the user.. Works Fine.
End Sub

End Module





-------------------------- --------------------------------------------

就像我说的那样,如果这与我的问题有关,请不要起诉。







问题:

这个MyControl用于a流程布局面板。每次运行搜索时,都会循环流布局面板,处理所有控件。一个SQL查询,然后用新控件填充FLPanel。



!!并且每次发生这种情况时,任务管理器中的内存使用量会增加0.07 mb。

我甚至尝试过调用,警告GC.Collect(),但没有运气释放内存。



如果重复搜索,则行为将继续,直到最终引发内存不足异常。





有谁知道这里发生了什么?我没有

请帮忙!





----------- ----更新--------------------------------------------- ---------------

事实证明,我的内存消耗来自正在使用的#fop块。从我读过的内容来看,这些是与托管对象相关联的弱引用。那么为什么调用垃圾收集器没有效果?



----------------------------------------------------------------------
Like I said, not sue if that's relevant to my problem.



Problem:
This MyControl is used in a flow layout panel. Every time a search is run, the flow layout panel is looped through, disposing of all controls. the an sql query, then fill the FLPanel with new Controls.

!! and every time this happens the memory usage in Task Manager bumps up by 0.07 mb.
I have even tried calling the, warned against, GC.Collect() but no luck in freeing the ram.

If the search is repeated then the behavior continues until finally the out of memory exception is raised.


Anybody know whats going on here? I don't
Please help!


--------------- Update ------------------------------------------------------------
So it turns out that my Memory consumption comes from the #of sink blocks in use. From what I've read, these are weak references that are associated with a managed object. So why would calling garbage collector have no effect?

推荐答案

不要在任务管理器中查看你的应用程序使用了多少内存。它在骗你!请改用PerfMon和.NET内存计数器。



任务管理器向您展示.NET CLR为您的应用程序保留了多少内存,而不是它实际使用了多少内存。
Do NOT look in Task Manager to see how much memory your app is using. It's lying to you! Use PerfMon and the .NET Memory counters instead.

Task Manager is showing you how much memory the .NET CLR is RESERVED for your app, not how much it's actually using.


你没有事实证明你的记忆正在泄漏。请参阅解决方案1.但是,这并不意味着您不能有内存泄漏,托管,非托管或两者兼而有之。您需要了解如何在托管和非托管内存以及其他资源的情况下完成内存清理。请查看我过去的答案:

WPF DataBinding中的内存泄漏 [ ^ ],

MDI表格中的内存管理 [ ^ ],

摆脱公众的最佳途径静态列表导致内存不足 [ ^ ],

Garbage collectotion负责所有内存管理 [ ^ ],
当CLR执行自动内存管理和GC? [ ^ ]。



对不起这些答案中的某些冗余,但引用它们仍然比重复它更好。请阅读,希望它能帮助您理解事情。



-SA
You don't have a proven fact that your memory is leaking. See Solution 1. However, it does not mean that you cannot have memory leak, managed, unmanaged or both. You need to understand how memory clean up is done, in case of managed and unmanaged memory, as well as other resources. Please see my past answers:
Memory leak in WPF DataBinding[^],
Memory management in MDI forms[^],
Best way to get rid of a public static List Causing an Out of Memory[^],
Garbage collectotion takes care of all the memory management[^],
When CLR Do Automatic Memory Management and GC?[^].

Sorry for certain redundancy in those answer, but referencing them is still better than repeating it all over. Please read, hope it will help you to understand things.

—SA


这篇关于用户控制未处置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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