zoukankan      html  css  js  c++  java
  • Dispose() C# 优化内存

    1       public void Dispose()
    2         {
    3             ((IDisposable)_designer).Dispose();
    4         }
     1      #region IDisposable Support
     2         private bool disposedValue = false; // 要检测冗余调用
     3 
     4         protected virtual void Dispose(bool disposing)
     5         {
     6             if (!disposedValue)
     7             {
     8                 if (disposing)
     9                 {
    10                     System.Runtime.InteropServices.Marshal.ReleaseComObject(this);
    11                     //this.Dispose();
    12                     // TODO: 释放托管状态(托管对象)。
    13                 }
    14                 // Use the feature cursor as required
    15                 System.Runtime.InteropServices.Marshal.ReleaseComObject(this);
    16                 // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。
    17                 // TODO: 将大型字段设置为 null。
    18 
    19                 disposedValue = true;
    20             }
    21         }
    22 
    23         // TODO: 仅当以上 Dispose(bool disposing) 拥有用于释放未托管资源的代码时才替代终结器。
    24         ~ItemCollectionBase()
    25         {
    26             // 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
    27             Dispose(false);
    28         }
    29 
    30         // 添加此代码以正确实现可处置模式。
    31         void IDisposable.Dispose()
    32         {
    33             // 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
    34             Dispose(true);
    35             // TODO: 如果在以上内容中替代了终结器,则取消注释以下行。
    36             GC.SuppressFinalize(this);
    37         }
    38         #endregion
       finally
                {
                    if (_graphics != null)
                        _graphics.Dispose();
                    if (_metaFile != null)
                        _metaFile.Dispose();
                    if (_stream != null)
                       _stream.Close();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(_graphics);//_graphics
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(_metaFile);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(_stream);
                }

      

       ~ChatRichTextBox()
            {
                // 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
                if (!IsDisposed)
                    this.Dispose();
                Dispose(true);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(this);//
                _oleObjectList = null;// ();
    
    
            }
    1 GC.Collect();
  • 相关阅读:
    ruby中的特殊字符
    android and webview
    ActiveRecord::Base.establish_connection
    Ruby 创建目录
    不能手动输入或粘贴
    eclipse找不到 help>software update>find and install
    PL/SQL 创建、查看、操作用户
    XML文件
    javascript 获取页面高度(多种浏览器)(转)
    Eclipse to android
  • 原文地址:https://www.cnblogs.com/endv/p/6170685.html
Copyright © 2011-2022 走看看