Infragistics NetAdvantage 控件资源释放问题的实际经验

    我们对于Infragistics NetAdvantage 的控件使用过的朋友一定都很了解了。非常好用的第三方控件。

    我目前使用该控件在8.1.20081.1000版本。

    该控件的使用的最多的是对于列表控件、下拉控件、数控件的使用

    这里主要说一下有关列表控件Infragistics.Win.UltraWinGrid.UltraGrid 的资源释放的问题。

      开发环境vs 2008

     语言:c#

     项目:Winform

    Infragistics.Win.UltraWinGrid.UltraGrid 这个控件是非常强大的,当我们在Winform中引用UltraGrid 后,一般情况下绑定资源后,关闭窗体,在正常使用的时候还不会发现资源释放的一些问题。但是,当在UltraGrid 中使用了下拉列的时候,问题就会出现了。如果UltraGrid 列类型为下拉类型的话,当下拉类型的数据数据源信息比较大的时候(一般大于1w条记录的时候),就会发现UltraGrid 对资源的消耗会比较大。

    这里说的列类型是下拉类型是指,将列的编辑控件设置为UltraCombo类型,既:


Infragistics.Win.UltraWinGrid.UltraGridColumn col=......

UltraCombo comb = new UltraCombo();

col.EditorControl = comb;

如下图所示:


如果性别列设定为下拉控件,则如下图结果


    以上为举例说明对于列表的列类型的设定方式。

    那么,如果上例子中性别列要是数据源不是男女两个记录源,而是1w个枚举值的话,那么就会出现一个问题。当关闭Winform的时候,资源不会被回收,而且在很长时间内,UltraGrid 的资源都不会回收,即使你在Winform窗体的 Closing事件中进行显示释放:UltraGrid .Disposed()资源,UltraGrid 内的资源也不会被完全释放。


    这样,当这样的类似窗体打开N多个的时候,就会出现问题了,内存只涨不跌(要是股票就好了^_^)

    那么这个问题的引起的原因是什么? 实际上是对UltraGrid 进行的资源释放,但是没有对UltraGrid 中的编辑控件进行显示释放。如果在释放UltraGrid 之前,将列的EditorControl 控件的资源也释放调,那么,GC垃圾才会知道回收这些已经Colse的窗体内的 UltraGrid 还存在的EditorControl 的资源。

    这里对于如何处理资源释放具体例子:

/// <summary>
        /// 释放列表中的列编辑控件EditorControl中类型为UltraCombo的资源
        /// </summary>
        /// <param name="bGridDisposed">是否也强制释放掉列表控件资源</param>
        public void ClearSource(bool bGridDisposed)
        {
            if (thisForm.dataGridView1.DataSource != null)
            {
                foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn c in thisForm.dataGridView1.DisplayLayout.Bands[0].Columns)
                {
                    if (c.EditorControl != null)
                    {
                        if (c.EditorControl.GetType() == typeof(UltraCombo))
                        {


                            UltraCombo uCombo = (c.EditorControl as UltraCombo);
                            uCombo.Dispose();
                            c.EditorControl = null;


                        }
                    }
                }
                if (bGridDisposed)
                {
                    thisForm.dataGridView1.Dispose();
                }


                //实际上对于资源的显示回收没有其太大作用,一下的语句可不用
                GC.Collect();  
                GC.WaitForPendingFinalizers();
            }
        }


该函数ClearSource()放在窗体的关闭事件中:

private void TestForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            ClearSource(true);
        }


    运行程序,观察任务管理器,你会明显发现,在任务管理器中,进程的资源会在一定的内存点上,(我观察的例子是70-100M之间),当打开N个这样的类似窗体,内存正常到一定的范围后,随窗体的关闭,再创建新的窗体的时候,进程内存会下降并维持在一个稳定的范围内.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
☆ 资料说明:☆ 压缩包内包含安装程序和注册机; Like Windows 8, Infragistics brings together the best of the PC and tablet in this suite. Impress and innovate with premier controls for data visualization. No matter what the platform or category, apps created with NetAdvantage for Windows UI will be bold, performant, and drive revenue thorugh the Windows Store. Fast & Fluid Maximize your apps with a Grid control designed for stylablity and high performance. Data and UI virtualization make this Grid lightweight and extremely fast when handling large amounts of data. This control allows you to display your data in the style and matter that best fits your needs. Drill, down, edit, delete, select, sort, group, and filter rows using your mouse, keyboard, or touch gestures. Innovative Charting Let your data tell the story, with the broadest range of interactive, high-performance Data Charts that include support for a full range of business, scientific, and financial charting scenarios, as well as trend line capabilities "right out of the box." This Data Chart is a next-generation charting control designed for handling a live data feed coming in with over tens of thousands of data point every several milliseconds. Touch Optimized Deliver the latest Touch UI with our new gesture supported controls - like our Editor controls - without needing to write code separately for mouse vs. touchscreen inputs. Touch support across HTML5 and XAML controls offers larger buttons and gesture-friendly UI for commonly used interactions like grouping, multiple sorting, multiple selection, scrolling, and more - no plug-ins or extensions needed. Reference App The Running Total app, which uses our XAML and HTML Chart and Map controls, is an end-to-end application that delivers a true Windows 8 experience, designed with best practices and performance. Included in the Running Total app are assemblies for a variety of Chart types, with trend lines, finanacial indicators, touch-first features, and our Geospatial Mapping controls, which support multiple tile sources and geo-imagery features.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值