日期:2014-05-18  浏览次数:20923 次

谁告诉下IDispose接口怎么用?
我有个winform程序,现在内存一直运行会不断增加,我所有控件能dispose和close的全部都用了,但是内存还是在增加,
网上看了下用IDispose,但是不知道怎么用。。
比如我自定义一个CloseForm方法,里面就是释放所有组件,那我这个怎么转接到IDispose上呢?
C# code

        /// <summary>
        /// 关闭窗体
        /// </summary>
        private void CloseFrom()
        {
            if (t != null && t.IsAlive)
            {
                t.Abort();
                t = null;
            }
            if (thumbnail != null)
            {
                thumbnail = null;
                thumbnail.Dispose();
            }
            if (tempBit != null)
            {
                tempBit.Dispose();
                tempBit = null;
            }
            if (tempBitmap != null)
            {
                tempBitmap.Dispose();
                tempBitmap = null;
            }
            if (dsImage != null)
            {
                dsImage.Dispose();
                dsImage = null;
            }
            if (img != null)
            {
                img.Dispose();
                img = null;
            }

            #region 释放控件
            this.pbHeadPicture.Image.Dispose();
            this.pbHeadPicture.Dispose();
            this.pbHeadPicture = null;
            this.pnlAdjustment.BackgroundImage.Dispose();
            this.pnlAdjustment.Dispose();
            this.pnlAdjustment = null;
            this.pnlGender2.Dispose();
            this.pnlGender2 = null;
            this.pnlPhotoBG.Dispose();
            this.pnlPhotoBG = null;
            this.picClose.Image.Dispose();
            this.picClose.Dispose();
            this.picClose = null;
            this.picFemale.Dispose();
            this.picFemale.Dispose();
            this.picFemale = null;
            this.picGenderOK.Image.Dispose();
            this.picGenderOK.Dispose();
            this.picGenderOK = null;
            this.picGenderReturn.Image.Dispose();
            this.picGenderReturn.Dispose();
            this.picGenderReturn = null;
            this.picJia.Image.Dispose();
            this.picJia.Dispose();
            this.picJia = null;
            this.picJian.Image.Dispose();
            this.picJian.Dispose();
            this.picJian = null;
            this.picLeft.Image.Dispose();
            this.picLeft.Dispose();
            this.picLeft = null;
            this.picMale.Image.Dispose();
            this.picMale.Dispose();
            this.picMale = null;
            this.picOK.Image.Dispose();
            this.picOK.Dispose();
            this.picOK = null;
            this.picReturn.Image.Dispose();
            this.picReturn.Dispose();
            this.picReturn = null;
            this.picRight.Image.Dispose();
            this.picRight.Dispose();
            this.picRight = null;
            this.picJiaoCheng.Image.Dispose();
            this.picJiaoCheng.Dispose();
            this.picJiaoCheng = null;
            #endregion

            if (apfShowPicture != null)
            {
                apfShowPicture.Dispose();
                apfShowPicture = null;
            }
            if (transKuangForm != null)
            {
                transKuangForm.Dispose();
                transKuangForm.Close();
                transKuangForm = null;
            }
            if (controlForm != null)
            {
                controlForm.Dispose();
                controlForm.Close();
                controlForm = null;
            }
            if (dengDaiForm != null)
            {
                dengDaiForm.Dispose();
                dengDaiForm.Close();
                dengDaiForm = null;
            }
            this.Dispose();
        }
//怎么和这个结合起来呢?
class R:IDisposable  
{  
    R()  
    {}  
    ~R()  
    {  
        Dispose(false);  
    }  
    public void Dispose()  
    {  
        GC.SuppressFinalize(this);  
        Dispose(true);