{"id":491,"date":"2016-04-22T17:25:30","date_gmt":"2016-04-22T17:25:30","guid":{"rendered":"559cb990c9dffd8675f6bc2186971dc2"},"modified":"2016-04-22T17:25:30","modified_gmt":"2016-04-22T17:25:30","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/491","title":{"rendered":".NET \u8d44\u6e90\u56de\u6536"},"content":{"rendered":"<p><b>MSDN\u5efa\u8bae\u6309\u7167\u4e0b\u9762\u7684\u6a21\u5f0f\u5b9e\u73b0IDisposable\u63a5\u53e3\uff1a<\/b><\/p>\n<table style=\"width:100%;background-color:#CCCCCC;\" align=\"left\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td>&nbsp;public class Foo: IDisposable<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; public void Dispose()<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dispose(true);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GC.SuppressFinalize(this);<br \/>\n&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp;&nbsp; protected virtual void Dispose(bool disposing)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!m_disposed)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (disposing)<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Release managed resources<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Release unmanaged resources<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_disposed = true;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; ~Foo()<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dispose(false);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; private bool m_disposed;<br \/>\n}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>CSDN\u4e0a\u4e00\u4f4d\u9ad8\u624b\u7684\u603b\u7ed3<\/b><\/p>\n<p>1\u3001Finalize\u65b9\u6cd5\uff08C#\u4e2d\u662f\u6790\u6784\u51fd\u6570\uff0c\u4ee5\u4e0b\u79f0\u6790\u6784\u51fd\u6570\uff09\u662f\u7528\u4e8e\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u7684\uff0c\u800c\u6258\u7ba1\u8d44\u6e90\u4f1a\u7531GC\u81ea\u52a8\u56de\u6536\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u8fd9\u6837\u6765\u533a\u5206 \u6258\u7ba1\u548c\u975e\u6258\u7ba1\u8d44\u6e90\u3002\u6240\u6709\u4f1a\u7531GC\u81ea\u52a8\u56de\u6536\u7684\u8d44\u6e90\uff0c\u5c31\u662f\u6258\u7ba1\u7684\u8d44\u6e90\uff0c\u800c\u4e0d\u80fd\u7531GC\u81ea\u52a8\u56de\u6536\u7684\u8d44\u6e90\uff0c\u5c31\u662f\u975e\u6258\u7ba1\u8d44\u6e90\u3002\u5728\u6211\u4eec\u7684\u7c7b\u4e2d\u76f4\u63a5\u4f7f\u7528\u975e\u6258\u7ba1\u8d44\u6e90\u7684\u60c5\u51b5\u5f88 \u5c11\uff0c\u6240\u4ee5\u57fa\u672c\u4e0a\u4e0d\u7528\u6211\u4eec\u5199\u6790\u6784\u51fd\u6570\u3002 <\/p>\n<p>2\u3001\u5927\u90e8\u5206\u7684\u975e\u6258\u7ba1\u8d44\u6e90\u4f1a\u7ed9\u7cfb\u7edf\u5e26\u6765\u5f88\u591a\u8d1f\u9762\u5f71\u54cd\uff0c\u4f8b\u5982\u6570\u636e\u5e93\u8fde\u63a5\u4e0d\u88ab\u91ca\u653e\u5c31\u53ef\u80fd\u5bfc\u81f4\u8fde\u63a5\u6c60\u4e2d\u7684\u53ef\u7528\u6570\u636e\u5e93\u8fde\u63a5\u7528\u5c3d\u3002\u6587\u4ef6\u4e0d\u5173\u95ed\u4f1a\u5bfc\u81f4\u5176\u5b83\u8fdb\u7a0b\u65e0\u6cd5\u8bfb\u5199\u8fd9\u4e2a\u6587\u4ef6\u7b49\u7b49\u3002 <\/p>\n<p>\u5b9e\u73b0\u6a21\u578b\uff1a <br \/>\n1\u3001\u7531\u4e8e\u5927\u591a\u6570\u7684\u975e\u6258\u7ba1\u8d44\u6e90\u90fd\u8981\u6c42\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u5e94\u8be5\u4e13\u95e8\u4e3a\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u516c\u5f00\u4e00\u4e2a\u65b9\u6cd5\u3002\u5b9e\u73b0IDispose\u63a5\u53e3\u7684Dispose\u65b9\u6cd5\u662f\u6700\u597d\u7684\u6a21\u578b\uff0c\u56e0\u4e3aC#\u652f\u6301using\u8bed\u53e5\u5feb\uff0c\u53ef\u4ee5\u5728\u79bb\u5f00\u8bed\u53e5\u5757\u65f6\u81ea\u52a8\u8c03\u7528Dispose\u65b9\u6cd5\u3002 <\/p>\n<p>2\u3001\u867d\u7136\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u6211\u4eec\u4ecd\u7136\u8981\u5728\u6790\u6784\u51fd\u6570\u4e2d\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u8fd9\u6837\u624d\u662f\u5b89\u5168\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5426\u5219\u5982\u679c\u56e0\u4e3a\u7a0b\u5e8f\u5458\u7684\u758f\u5ffd\u5fd8\u8bb0\u4e86\u624b\u52a8\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c \u90a3\u4e48\u5c31\u4f1a\u5e26\u6765\u707e\u96be\u6027\u7684\u540e\u679c\u3002\u6240\u4ee5\u8bf4\u5728\u6790\u6784\u51fd\u6570\u4e2d\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u662f\u4e00\u79cd\u8865\u6551\u7684\u63aa\u65bd\uff0c\u81f3\u5c11\u5bf9\u4e8e\u5927\u591a\u6570\u7c7b\u6765\u8bf4\u662f\u5982\u6b64\u3002 <\/p>\n<p>3\u3001\u7531\u4e8e\u6790\u6784\u51fd\u6570\u7684\u8c03\u7528\u5c06\u5bfc\u81f4GC\u5bf9\u5bf9\u8c61\u56de\u6536\u7684\u6548\u7387\u964d\u4f4e\uff0c\u6240\u4ee5\u5982\u679c\u5df2\u7ecf\u5b8c\u6210\u4e86\u6790\u6784\u51fd\u6570\u8be5\u5e72\u7684\u4e8b\u60c5\uff08\u4f8b\u5982\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff09\uff0c\u5c31\u5e94\u5f53\u4f7f\u7528SuppressFinalize\u65b9\u6cd5\u544a\u8bc9GC\u4e0d\u9700\u8981\u518d\u6267\u884c\u67d0\u4e2a\u5bf9\u8c61\u7684\u6790\u6784\u51fd\u6570\u3002 <\/p>\n<p>4\u3001\u6790\u6784\u51fd\u6570\u4e2d\u53ea\u80fd\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u800c\u4e0d\u80fd\u5bf9\u4efb\u4f55\u6258\u7ba1\u7684\u5bf9\u8c61\/\u8d44\u6e90\u8fdb\u884c\u64cd\u4f5c\u3002\u56e0\u4e3a\u4f60\u65e0\u6cd5\u9884\u6d4b\u6790\u6784\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u673a\uff0c\u6240\u4ee5\uff0c\u5f53\u6790\u6784\u51fd\u6570\u88ab\u6267\u884c\u7684\u65f6\u5019\uff0c\u4e5f\u8bb8\u4f60\u8fdb\u884c\u64cd\u4f5c\u7684\u6258\u7ba1\u8d44\u6e90\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86\u3002\u8fd9\u6837\u5c06\u5bfc\u81f4\u4e25\u91cd\u7684\u540e\u679c\u3002 <\/p>\n<p>5\u3001\uff08\u8fd9\u662f\u4e00\u4e2a\u89c4\u5219\uff09\u5982\u679c\u4e00\u4e2a\u7c7b\u62e5\u6709\u4e00\u4e2a\u5b9e\u73b0\u4e86IDispose\u63a5\u53e3\u7c7b\u578b\u7684\u6210\u5458\uff0c\u5e76\u521b\u5efa\uff08\u6ce8\u610f\u662f\u521b\u5efa\uff0c\u800c\u4e0d\u662f\u63a5\u6536\uff0c\u5fc5\u987b\u662f\u7531\u7c7b\u81ea\u5df1\u521b\u5efa\uff09\u5b83\u7684\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u5219 \u8fd9\u4e2a\u7c7b\u4e5f\u5e94\u8be5\u5b9e\u73b0IDispose\u63a5\u53e3\uff0c\u5e76\u5728Dispose\u65b9\u6cd5\u4e2d\u8c03\u7528\u6240\u6709\u5b9e\u73b0\u4e86IDispose\u63a5\u53e3\u7684\u6210\u5458\u7684Dispose\u65b9\u6cd5\u3002 <br \/>\n\u53ea\u6709\u8fd9\u6837\u7684\u624d\u80fd\u4fdd\u8bc1\u6240\u6709\u5b9e\u73b0\u4e86IDispose\u63a5\u53e3\u7684\u7c7b\u7684\u5bf9\u8c61\u7684Dispose\u65b9\u6cd5\u80fd\u591f\u88ab\u8c03\u7528\u5230\uff0c\u786e\u4fdd\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\u4efb\u4f55\u9700\u8981\u91ca\u653e\u7684\u8d44\u6e90\u3002<\/p>\n<p><b>\u8fdb\u9636\uff1a<\/b> <\/p>\n<p>\u5728.NET\u7684\u5bf9\u8c61\u4e2d\u5b9e\u9645\u4e0a\u6709\u4e24\u4e2a\u7528\u4e8e\u91ca\u653e\u8d44\u6e90\u7684\u51fd\u6570\uff1aDispose\u548cFinalize\u3002Finalize\u7684\u76ee\u7684\u662f\u7528\u4e8e\u91ca\u653e\u975e\u6258\u7ba1\u7684\u8d44\u6e90\uff0c\u800cDispose\u662f\u7528\u4e8e\u91ca\u653e\u6240\u6709\u8d44\u6e90\uff0c\u5305\u62ec\u6258\u7ba1\u7684\u548c\u975e\u6258\u7ba1\u7684\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u6a21\u5f0f\u4e2d\uff0cvoid Dispose(bool disposing)\u51fd\u6570\u901a\u8fc7\u4e00\u4e2adisposing\u53c2\u6570\u6765\u533a\u522b\u5f53\u524d\u662f\u5426\u662f\u88abDispose()\u8c03\u7528\u3002\u5982\u679c\u662f\u88abDispose()\u8c03\u7528\uff0c\u90a3\u4e48\u9700\u8981\u540c\u65f6\u91ca\u653e \u6258\u7ba1\u548c\u975e\u6258\u7ba1\u7684\u8d44\u6e90\u3002\u5982\u679c\u662f\u88ab~Foo()\uff08\u4e5f\u5c31\u662fC#\u7684Finalize()\uff09\u8c03\u7528\u4e86\uff0c\u90a3\u4e48\u53ea\u9700\u8981\u91ca\u653e\u975e\u6258\u7ba1\u7684\u8d44\u6e90\u5373\u53ef\u3002<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\uff0cDispose()\u51fd\u6570\u662f\u88ab\u5176\u5b83\u4ee3\u7801\u663e\u5f0f\u8c03\u7528\u5e76\u8981\u6c42\u91ca\u653e\u8d44\u6e90\u7684\uff0c\u800cFinalize\u662f\u88abGC\u8c03\u7528\u7684\u3002\u5728GC\u8c03\u7528\u7684\u65f6\u5019Foo\u6240\u5f15\u7528\u7684\u5176\u5b83 \u6258\u7ba1\u5bf9\u8c61\u53ef\u80fd\u8fd8\u4e0d\u9700\u8981\u88ab\u9500\u6bc1\uff0c\u5e76\u4e14\u5373\u4f7f\u8981\u9500\u6bc1\uff0c\u4e5f\u4f1a\u7531GC\u6765\u8c03\u7528\u3002\u56e0\u6b64\u5728Finalize\u4e2d\u53ea\u9700\u8981\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u5373\u53ef\u3002\u53e6\u5916\u4e00\u65b9\u9762\uff0c\u7531\u4e8e\u5728 Dispose()\u4e2d\u5df2\u7ecf\u91ca\u653e\u4e86\u6258\u7ba1\u548c\u975e\u6258\u7ba1\u7684\u8d44\u6e90\uff0c\u56e0\u6b64\u5728\u5bf9\u8c61\u88abGC\u56de\u6536\u65f6\u518d\u6b21\u8c03\u7528Finalize\u662f\u6ca1\u6709\u5fc5\u8981\u7684\uff0c\u6240\u4ee5\u5728Dispose()\u4e2d\u8c03\u7528 GC.SuppressFinalize(this)\u907f\u514d\u91cd\u590d\u8c03\u7528Finalize\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5373\u4f7f\u91cd\u590d\u8c03\u7528Finalize\u548cDispose\u4e5f\u662f\u4e0d\u5b58\u5728\u95ee\u9898\u7684\uff0c\u56e0\u4e3a\u6709\u53d8\u91cfm_disposed\u7684\u5b58\u5728\uff0c\u8d44\u6e90\u53ea\u4f1a\u88ab\u91ca\u653e\u4e00\u6b21\uff0c\u591a\u4f59\u7684\u8c03\u7528\u4f1a\u88ab\u5ffd\u7565\u8fc7\u53bb\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u4e0a\u9762\u7684\u6a21\u5f0f\u4fdd\u8bc1\u4e86\uff1a<\/p>\n<p>1\u3001 Finalize\u53ea\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff1b<\/p>\n<p>2\u3001 Dispose\u91ca\u653e\u6258\u7ba1\u548c\u975e\u6258\u7ba1\u8d44\u6e90\uff1b<\/p>\n<p>3\u3001 \u91cd\u590d\u8c03\u7528Finalize\u548cDispose\u662f\u6ca1\u6709\u95ee\u9898\u7684\uff1b<\/p>\n<p>4\u3001 Finalize\u548cDispose\u5171\u4eab\u76f8\u540c\u7684\u8d44\u6e90\u91ca\u653e\u7b56\u7565\uff0c\u56e0\u6b64\u4ed6\u4eec\u4e4b\u95f4\u4e5f\u662f\u6ca1\u6709\u51b2\u7a81\u7684\u3002<\/p>\n<p>\u5728C#\u4e2d\uff0c\u8fd9\u4e2a\u6a21\u5f0f\u9700\u8981\u663e\u5f0f\u5730\u5b9e\u73b0\uff0c\u5176\u4e2dC#\u7684~Foo()\u51fd\u6570\u4ee3\u8868\u4e86Finalize()\u3002\u800c\u5728C++\/CLI\u4e2d\uff0c\u8fd9\u4e2a\u6a21\u5f0f\u662f\u81ea\u52a8\u5b9e\u73b0\u7684\uff0cC++\u7684\u7c7b\u6790\u6784\u51fd\u6570\u5219\u662f\u4e0d\u4e00\u6837\u7684\u3002<\/p>\n<p>\u6309\u7167C++\u8bed\u4e49\uff0c\u6790\u6784\u51fd\u6570\u5728\u8d85\u51fa\u4f5c\u7528\u57df\uff0c\u6216\u8005delete\u7684\u65f6\u5019\u88ab\u8c03\u7528\u3002\u5728Managed C++\uff08\u5373.NET 1.1\u4e2d\u7684\u6258\u7ba1C++\uff09\u4e2d\uff0c\u6790\u6784\u51fd\u6570\u76f8\u5f53\u4e8eCLR\u4e2d\u7684Finalize()\u65b9\u6cd5\uff0c\u5728\u5783\u573e\u6536\u96c6\u7684\u65f6\u5019\u7531GC\u8c03\u7528\uff0c\u56e0\u6b64\uff0c\u8c03\u7528\u7684\u65f6\u673a\u662f\u4e0d\u660e\u786e\u7684\u3002\u5728.NET 2.0\u7684C++\/CLI\u4e2d\uff0c\u6790\u6784\u51fd\u6570\u7684\u8bed\u4e49\u88ab\u4fee\u6539\u4e3a\u7b49\u4ef7\u4e0eDispose()\u65b9\u6cd5\uff0c\u8fd9\u5c31\u9690\u542b\u4e86\u4e24\u4ef6\u4e8b\u60c5\uff1a<\/p>\n<p>1\u3001 \u6240\u6709\u7684C++\/CLI\u4e2d\u7684CLR\u7c7b\u90fd\u5b9e\u73b0\u4e86\u63a5\u53e3IDisposable\uff0c\u56e0\u6b64\u5728C#\u4e2d\u53ef\u4ee5\u7528using\u5173\u952e\u5b57\u6765\u8bbf\u95ee\u8fd9\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u3002<\/p>\n<p>2\u3001 \u6790\u6784\u51fd\u6570\u4e0d\u518d\u7b49\u4ef7\u4e8eFinalize()\u4e86\u3002<\/p>\n<p>\u5bf9\u4e8e\u7b2c\u4e00\u70b9\uff0c\u8fd9\u662f\u4e00\u4ef6\u597d\u4e8b\uff0c\u6211\u8ba4\u4e3a\u5728\u8bed\u4e49\u4e0aDispose()\u66f4\u52a0\u63a5\u8fd1\u4e8eC++\u6790\u6784\u51fd\u6570\u3002\u5bf9\u4e8e\u7b2c\u4e8c\u70b9\uff0cMicrosoft\u8fdb\u884c\u4e86\u4e00\u6b21\u6269\u5c55\uff0c\u505a\u6cd5\u662f\u5f15\u5165\u4e86\u201c\uff01\u201d\u51fd\u6570\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>public ref class Foo<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; public:<br \/>\n&nbsp;&nbsp;&nbsp; Foo();<br \/>\n&nbsp;&nbsp;&nbsp; ~Foo(); \/\/ destructor<br \/>\n&nbsp;&nbsp;&nbsp; !Foo(); \/\/ finalizer<br \/>\n};<\/p>\n<p>\n\u201c\uff01\u201d\u51fd\u6570\uff08\u6211\u5b9e\u5728\u4e0d\u77e5\u9053\u5e94\u8be5\u600e\u4e48\u79f0\u547c\u5b83\uff09\u53d6\u4ee3\u539f\u6765Managed C++\u4e2d\u7684Finalize()\u88abGC\u8c03\u7528\u3002MSDN\u5efa\u8bae\uff0c\u4e3a\u4e86\u51cf\u5c11\u4ee3\u7801\u7684\u91cd\u590d\uff0c\u53ef\u4ee5\u5199\u8fd9\u6837\u7684\u4ee3\u7801\uff1a<\/p>\n<p>~Foo()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; \/\/\u91ca\u653e\u6258\u7ba1\u7684\u8d44\u6e90<br \/>\n&nbsp;&nbsp;&nbsp; this-&gt;!Foo();<br \/>\n}<\/p>\n<p>!Foo()<br \/>\n{<br \/>\n\/\/\u91ca\u653e\u975e\u6258\u7ba1\u7684\u8d44\u6e90<br \/>\n}<\/p>\n<p>\n\u5bf9\u4e8e\u4e0a\u9762\u8fd9\u4e2a\u7c7b\uff0c\u5b9e\u9645\u4e0aC++\/CLI\u751f\u6210\u5bf9\u5e94\u7684C#\u4ee3\u7801\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p>&nbsp; <\/p>\n<table style=\"background-color:#cccccc;width:100%;\" align=\"left\" height=\"858\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td>&nbsp;public class Foo<br \/>\n{<\/p>\n<p>&nbsp;&nbsp;&nbsp; private void !Foo()<\/p>\n<p>&nbsp;&nbsp; &nbsp;{<br \/>\n&nbsp;&nbsp; &nbsp;\/\/ \u91ca\u653e\u975e\u6258\u7ba1\u7684\u8d44\u6e90<br \/>\n&nbsp;&nbsp; &nbsp;}<\/p>\n<p>&nbsp;&nbsp; &nbsp;private void ~Foo()<br \/>\n&nbsp;&nbsp; &nbsp;{<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; \/\/ \u91ca\u653e\u6258\u7ba1\u7684\u8d44\u6e90<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; !Foo();<br \/>\n&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp; <br \/>\n&nbsp;&nbsp; &nbsp; public Foo() <br \/>\n&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp; <br \/>\n&nbsp;&nbsp; &nbsp; public void Dispose()<br \/>\n&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; Dispose(true);<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; GC.SuppressFinalize(this);<br \/>\n&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp; <br \/>\n&nbsp;&nbsp; &nbsp; protected virtual void Dispose(bool disposing)<br \/>\n&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if (disposing)<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;~Foo();<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; else<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; try<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;!Foo();<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; finally<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;base.Finalize();<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp; }<br \/>\n&nbsp;&nbsp; &nbsp; <br \/>\n&nbsp;&nbsp; &nbsp; protected void Finalize()<br \/>\n&nbsp;&nbsp; &nbsp; {<br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Dispose(false);<br \/>\n&nbsp;&nbsp; &nbsp; }<br \/>\n}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp; <\/p>\n<p>\u7531\u4e8e~Foo()\u548c!Foo()\u4e0d\u4f1a\u88ab\u91cd\u590d\u8c03\u7528\uff08\u81f3\u5c11MS\u8fd9\u6837\u8ba4\u4e3a\uff09\uff0c\u56e0\u6b64\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\u6ca1\u6709\u548c\u524d\u9762m_disposed\u76f8\u540c\u7684\u53d8\u91cf\uff0c\u4f46\u662f\u57fa\u672c\u7684\u7ed3\u6784\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\n<br \/>\n\u5e76\u4e14\uff0c\u53ef\u4ee5\u770b\u5230\u5b9e\u9645\u4e0a\u5e76\u4e0d\u662f~Foo()\u548c!Foo()\u5c31\u662fDispose\u548cFinalize\uff0c\u800c\u662fC++\/CLI\u7f16\u8bd1\u5668\u751f\u6210\u4e86\u4e24\u4e2aDispose \u548cFinalize\u51fd\u6570\uff0c\u5e76\u5728\u5408\u9002\u7684\u65f6\u5019\u8c03\u7528\u5b83\u4eec\u3002C++\/CLI\u5176\u5b9e\u5df2\u7ecf\u505a\u4e86\u5f88\u591a\u5de5\u4f5c\uff0c\u4f46\u662f\u552f\u4e00\u7684\u4e00\u4e2a\u95ee\u9898\u5c31\u662f\u4f9d\u8d56\u4e8e\u7528\u6237\u5728~Foo()\u4e2d\u8c03 \u7528!Foo()\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><b>\u4ed6\u4eba\u5199\u7684\u4e00\u6bb5\u5c0f\u7a0b\u5e8f<\/b>\uff08\u4ec5\u62f7\u8d1d\uff0c\u672a\u9a8c\u8bc1\uff09<\/p>\n<p>&nbsp;\u6d4b\u8bd5\uff1a<\/p>\n<table style=\"width:100%;background-color:#CCCCCC;\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td>&nbsp;<\/p>\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">public<\/code>&nbsp;<code class=\"csharp keyword\">class<\/code>&nbsp;<code class=\"csharp plain\">b&nbsp;:&nbsp;IDisposable<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">{<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">public<\/code>&nbsp;<code class=\"csharp keyword\">int<\/code>&nbsp;<code class=\"csharp plain\">i;<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">public<\/code>&nbsp;<code class=\"csharp plain\">b()&nbsp;{&nbsp;Console.WriteLine(<\/code><code class=\"csharp string\">\"ctor\"<\/code><code class=\"csharp plain\">);&nbsp;}<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">~b()&nbsp;{&nbsp;Console.WriteLine(<\/code><code class=\"csharp string\">\"dtor\"<\/code><code class=\"csharp plain\">);&nbsp;}<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">public<\/code>&nbsp;<code class=\"csharp keyword\">void<\/code>&nbsp;<code class=\"csharp plain\">Dispose()<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">{<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">Console.WriteLine(<\/code><code class=\"csharp string\">\"Dispose\"<\/code><code class=\"csharp plain\">);<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">GC.SuppressFinalize(<\/code><code class=\"csharp keyword\">true<\/code><code class=\"csharp plain\">);<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">}<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">}<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">class<\/code>&nbsp;<code class=\"csharp plain\">Program<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">{<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">static<\/code>&nbsp;<code class=\"csharp keyword\">void<\/code>&nbsp;<code class=\"csharp plain\">Main(<\/code><code class=\"csharp keyword\">string<\/code><code class=\"csharp plain\">[]&nbsp;args)<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">{<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">b&nbsp;objb&nbsp;=&nbsp;<\/code><code class=\"csharp keyword\">new<\/code>&nbsp;<code class=\"csharp plain\">b&nbsp;{&nbsp;i&nbsp;=&nbsp;2&nbsp;};<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp keyword\">using<\/code>&nbsp;<code class=\"csharp plain\">(objb)<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">{<\/code><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">Console.WriteLine(<\/code><code class=\"csharp string\">\"using\"<\/code><code class=\"csharp plain\">);<\/code><\/div>\n<div class=\"line number20 index19 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">}<\/code><\/div>\n<div class=\"line number21 index20 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">Console.WriteLine(<\/code><code class=\"csharp string\">\"after&nbsp;using\"<\/code><code class=\"csharp plain\">);<\/code><\/div>\n<div class=\"line number22 index21 alt1\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">}<\/code><\/div>\n<div class=\"line number23 index22 alt2\"><code class=\"csharp spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"csharp plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp; \u8f93\u51fa\uff1a<\/p>\n<table style=\"width:100%;background-color:#CCCCCC;\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"0\" cellspacing=\"0\">\n<tbody>\n<tr>\n<td>&nbsp;<\/p>\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"csharp plain\">ctor<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"csharp keyword\">using<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"csharp plain\">Dispose<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"csharp plain\">after&nbsp;<\/code><code class=\"csharp keyword\">using<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"csharp plain\">dtor<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"csharp plain\">Press&nbsp;any&nbsp;key&nbsp;to&nbsp;<\/code><code class=\"csharp keyword\">continue<\/code>&nbsp;<code class=\"csharp plain\">.&nbsp;.&nbsp;.<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p><b>CSDN\u4e0a\u4e00\u4f4d\u9ad8\u624b\u7684\u603b\u7ed3<\/b><\/p>\n<p>1\u3001Finalize\u65b9\u6cd5\uff08C#\u4e2d\u662f\u6790\u6784\u51fd\u6570\uff0c\u4ee5\u4e0b\u79f0\u6790\u6784\u51fd\u6570\uff09\u662f\u7528\u4e8e\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u7684\uff0c\u800c\u6258\u7ba1\u8d44\u6e90\u4f1a\u7531GC\u81ea\u52a8\u56de\u6536\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u8fd9\u6837\u6765\u533a\u5206<\/p>\n<p>\u6258\u7ba1\u548c\u975e\u6258\u7ba1\u8d44\u6e90\u3002\u6240\u6709\u4f1a\u7531GC\u81ea\u52a8\u56de\u6536\u7684\u8d44\u6e90\uff0c\u5c31\u662f\u6258\u7ba1\u7684\u8d44\u6e90\uff0c\u800c\u4e0d\u80fd\u7531GC\u81ea\u52a8\u56de\u6536\u7684\u8d44\u6e90\uff0c\u5c31\u662f\u975e\u6258\u7ba1\u8d44\u6e90\u3002\u5728\u6211\u4eec\u7684\u7c7b\u4e2d\u76f4\u63a5\u4f7f\u7528\u975e\u6258\u7ba1\u8d44\u6e90\u7684\u60c5\u51b5\u5f88<br \/>\n \u5c11\uff0c\u6240\u4ee5\u57fa\u672c\u4e0a\u4e0d\u7528\u6211\u4eec\u5199\u6790\u6784\u51fd\u6570\u3002 <\/p>\n<p>2\u3001\u5927\u90e8\u5206\u7684\u975e\u6258\u7ba1\u8d44\u6e90\u4f1a\u7ed9\u7cfb\u7edf\u5e26\u6765\u5f88\u591a\u8d1f\u9762\u5f71\u54cd\uff0c\u4f8b\u5982\u6570\u636e\u5e93\u8fde\u63a5\u4e0d\u88ab\u91ca\u653e\u5c31\u53ef\u80fd\u5bfc\u81f4\u8fde\u63a5\u6c60\u4e2d\u7684\u53ef\u7528\u6570\u636e\u5e93\u8fde\u63a5\u7528\u5c3d\u3002\u6587\u4ef6\u4e0d\u5173\u95ed\u4f1a\u5bfc\u81f4\u5176\u5b83\u8fdb\u7a0b\u65e0\u6cd5\u8bfb\u5199\u8fd9\u4e2a\u6587\u4ef6\u7b49\u7b49\u3002 <\/p>\n<p>\u5b9e\u73b0\u6a21\u578b\uff1a <br \/>\n1\u3001\u7531\u4e8e\u5927\u591a\u6570\u7684\u975e\u6258\u7ba1\u8d44\u6e90\u90fd\u8981\u6c42\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u5e94\u8be5\u4e13\u95e8\u4e3a\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u516c\u5f00\u4e00\u4e2a\u65b9\u6cd5\u3002\u5b9e\u73b0IDispose\u63a5\u53e3\u7684Dispose\u65b9\u6cd5\u662f\u6700\u597d\u7684\u6a21\u578b\uff0c\u56e0\u4e3aC#\u652f\u6301using\u8bed\u53e5\u5feb\uff0c\u53ef\u4ee5\u5728\u79bb\u5f00\u8bed\u53e5\u5757\u65f6\u81ea\u52a8\u8c03\u7528Dispose\u65b9\u6cd5\u3002 <\/p>\n<p>2\u3001\u867d\u7136\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u6211\u4eec\u4ecd\u7136\u8981\u5728\u6790\u6784\u51fd\u6570\u4e2d\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u8fd9\u6837\u624d\u662f\u5b89\u5168\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5426\u5219\u5982\u679c\u56e0\u4e3a\u7a0b\u5e8f\u5458\u7684\u758f\u5ffd\u5fd8\u8bb0\u4e86\u624b\u52a8\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c \u90a3\u4e48\u5c31\u4f1a\u5e26\u6765\u707e\u96be\u6027\u7684\u540e\u679c\u3002\u6240\u4ee5\u8bf4\u5728\u6790\u6784\u51fd\u6570\u4e2d\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff0c\u662f\u4e00\u79cd\u8865\u6551\u7684\u63aa\u65bd\uff0c\u81f3\u5c11\u5bf9\u4e8e\u5927\u591a\u6570\u7c7b\u6765\u8bf4\u662f\u5982\u6b64\u3002 <\/p>\n<p>3\u3001\u7531\u4e8e\u6790\u6784\u51fd\u6570\u7684\u8c03\u7528\u5c06\u5bfc\u81f4GC\u5bf9\u5bf9\u8c61\u56de\u6536\u7684\u6548\u7387\u964d\u4f4e\uff0c\u6240\u4ee5\u5982\u679c\u5df2\u7ecf\u5b8c\u6210\u4e86\u6790\u6784\u51fd\u6570\u8be5\u5e72\u7684\u4e8b\u60c5\uff08\u4f8b\u5982\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\uff09\uff0c\u5c31\u5e94\u5f53\u4f7f\u7528SuppressFinalize\u65b9\u6cd5\u544a\u8bc9GC\u4e0d\u9700\u8981\u518d\u6267\u884c\u67d0\u4e2a\u5bf9\u8c61\u7684\u6790\u6784\u51fd\u6570\u3002 <\/p>\n<p>4\u3001\u6790\u6784\u51fd\u6570\u4e2d\u53ea\u80fd\u91ca\u653e\u975e\u6258\u7ba1\u8d44\u6e90\u800c\u4e0d\u80fd\u5bf9\u4efb\u4f55\u6258\u7ba1\u7684\u5bf9\u8c61\/\u8d44\u6e90\u8fdb\u884c\u64cd\u4f5c\u3002\u56e0\u4e3a\u4f60\u65e0\u6cd5\u9884\u6d4b\u6790\u6784\u51fd\u6570\u7684\u8fd0\u884c\u65f6\u673a\uff0c\u6240\u4ee5\uff0c\u5f53\u6790\u6784\u51fd\u6570\u88ab\u6267\u884c\u7684\u65f6\u5019\uff0c\u4e5f\u8bb8\u4f60\u8fdb\u884c\u64cd\u4f5c\u7684\u6258\u7ba1\u8d44\u6e90\u5df2\u7ecf\u88ab\u91ca\u653e\u4e86\u3002\u8fd9\u6837\u5c06\u5bfc\u81f4\u4e25\u91cd\u7684\u540e\u679c\u3002 <\/p>\n<p>5\u3001\uff08\u8fd9\u662f\u4e00\u4e2a\u89c4\u5219\uff09\u5982\u679c\u4e00\u4e2a\u7c7b\u62e5\u6709\u4e00\u4e2a\u5b9e\u73b0\u4e86IDispose\u63a5\u53e3\u7c7b\u578b\u7684\u6210\u5458\uff0c\u5e76\u521b\u5efa\uff08\u6ce8\u610f\u662f\u521b\u5efa\uff0c\u800c\u4e0d\u662f\u63a5\u6536\uff0c\u5fc5\u987b\u662f\u7531\u7c7b\u81ea\u5df1\u521b\u5efa\uff09\u5b83\u7684\u5b9e\u4f8b\u5bf9\u8c61\uff0c\u5219<br \/>\n \u8fd9\u4e2a\u7c7b\u4e5f\u5e94\u8be5\u5b9e\u73b0IDispose\u63a5\u53e3\uff0c\u5e76\u5728Dispose\u65b9\u6cd5\u4e2d\u8c03\u7528\u6240\u6709\u5b9e\u73b0\u4e86IDispose\u63a5\u53e3\u7684\u6210\u5458\u7684Dispose\u65b9\u6cd5\u3002 <br \/>\n\u53ea\u6709\u8fd9\u6837\u7684\u624d\u80fd\u4fdd\u8bc1\u6240\u6709\u5b9e\u73b0\u4e86IDispose\u63a5\u53e3\u7684\u7c7b\u7684\u5bf9\u8c61\u7684Dispose\u65b9\u6cd5\u80fd\u591f\u88ab\u8c03\u7528\u5230\uff0c\u786e\u4fdd\u53ef\u4ee5\u624b\u52a8\u91ca\u653e\u4efb\u4f55\u9700\u8981\u91ca\u653e\u7684\u8d44\u6e90\u3002<\/p>\n<p> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/491\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[279],"tags":[233],"class_list":["post-491","post","type-post","status-publish","format-standard","hentry","category-dotnet","tag-233"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=491"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}