﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-天行健,君子以自强不息-最新评论</title><link>http://www.cnblogs.com/pzmg/CommentsRSS.aspx</link><description /><language>zh-cn</language><pubDate>Wed, 22 Apr 2009 09:38:27 GMT</pubDate><lastBuildDate>Wed, 22 Apr 2009 09:38:27 GMT</lastBuildDate><generator>cnblogs</generator><item><title>Re:.net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/07/22/1397312.html#1592811</link><dc:creator>子逸</dc:creator><author>子逸</author><pubDate>Wed, 22 Jul 2009 10:56:53 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/07/22/1397312.html#1592811</guid><description><![CDATA[本来懂一点, 现在不懂了.<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">子逸</a> 2009-07-22 18:56 <a href="http://www.cnblogs.com/pzmg/archive/2009/07/22/1397312.html#1592811#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/25/1397312.html#1460599</link><dc:creator>iTech</dc:creator><author>iTech</author><pubDate>Wed, 25 Feb 2009 01:07:49 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/25/1397312.html#1460599</guid><description><![CDATA[恩，还不错！<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">iTech</a> 2009-02-25 09:07 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/25/1397312.html#1460599#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460432</link><dc:creator>Jonny Yu</dc:creator><author>Jonny Yu</author><pubDate>Tue, 24 Feb 2009 14:33:11 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460432</guid><description><![CDATA[--引用--------------------------------------------------
我的地盘我做主: 释放托管资源
感谢这位朋友指出的问题,确实像你所说的那样,如果这个类包含的字段在实现了IDispose的方法里面,对非托管资源进行了释放,如果吧_filed.Dispose(true)放在这里就是不合适的.应该把它放在清理非托管资源的区域.

那释放托管资源的地方应该写什么呢,我想这可能根据自己的代码逻辑来决定这里到底写些什么东西,比如在构造函数里面对事件进行了+=处理,那么在对应的这里就可以写事件的-=处理.
我是这样理解的,如果你觉得我的理解还是存在问题的话,希望阁下可以指点一二
再次感谢
--------------------------------------------------------

我怎么觉得就是应该放在if block里面呢. 因为GC在执行Finalizer的时候次序是随机的,所以很有可能等到你这个对象的Finalizer被执行的时候, 其引用的对象早已被Finalize掉了,这样再次finalize可能会引起异常,当然异常发上在GC thread上,可能觉察不到.<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">Jonny Yu</a> 2009-02-24 22:33 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460432#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460414</link><dc:creator>我的地盘我做主</dc:creator><author>我的地盘我做主</author><pubDate>Tue, 24 Feb 2009 14:05:41 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460414</guid><description><![CDATA[海洋——海纳百川,有容乃大<br/>我把代码放到Code里面折叠了一下,不知道你说的高亮是不是这个意思.<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">我的地盘我做主</a> 2009-02-24 22:05 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460414#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460406</link><dc:creator>我的地盘我做主</dc:creator><author>我的地盘我做主</author><pubDate>Tue, 24 Feb 2009 13:59:20 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460406</guid><description><![CDATA[释放托管资源<br/>感谢这位朋友指出的问题,确实像你所说的那样,如果这个类包含的字段在实现了IDispose的方法里面,对非托管资源进行了释放,如果吧_filed.Dispose(true)放在这里就是不合适的.应该把它放在清理非托管资源的区域.<br/><br/>那释放托管资源的地方应该写什么呢,我想这可能根据自己的代码逻辑来决定这里到底写些什么东西,比如在构造函数里面对事件进行了+=处理,那么在对应的这里就可以写事件的-=处理.<br/>我是这样理解的,如果你觉得我的理解还是存在问题的话,希望阁下可以指点一二<br/>再次感谢<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">我的地盘我做主</a> 2009-02-24 21:59 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460406#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460350</link><dc:creator>海洋——海纳百川,有容乃大.</dc:creator><author>海洋——海纳百川,有容乃大.</author><pubDate>Tue, 24 Feb 2009 13:07:46 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460350</guid><description><![CDATA[谢谢分享。 <br/>建议博主highlight 一下代码。呵呵。<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">海洋——海纳百川,有容乃大.</a> 2009-02-24 21:07 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460350#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460265</link><dc:creator>释放托管资源 </dc:creator><author>释放托管资源 </author><pubDate>Tue, 24 Feb 2009 11:03:53 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460265</guid><description><![CDATA[--引用--------------------------------------------------<br/>我的地盘我做主: 如果这个类含有的字段实现了IDispose接口,我们可以在这个地方调用这个字段的Dispose()方法<br/><br/><br/><br/>if(isDisposing)<br/><br/><br/><br/>{<br/><br/><br/><br/>_filed.Dispose();<br/><br/><br/><br/>}<br/><br/><br/>--------------------------------------------------------<br/>那Finalize调用时，对象里面非托管对象不就没办法释放？<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">释放托管资源 </a> 2009-02-24 19:03 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460265#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460197</link><dc:creator>我的地盘我做主</dc:creator><author>我的地盘我做主</author><pubDate>Tue, 24 Feb 2009 09:44:54 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460197</guid><description><![CDATA[如果这个类含有的字段实现了IDispose接口,我们可以在这个地方调用这个字段的Dispose()方法
<br/>
<br/>if(isDisposing)
<br/>
<br/>{
<br/>
<br/>_filed.Dispose();
<br/>
<br/>}
<br/><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">我的地盘我做主</a> 2009-02-24 17:44 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460197#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re:.net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460196</link><dc:creator>lsjwzh</dc:creator><author>lsjwzh</author><pubDate>Tue, 24 Feb 2009 09:44:05 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460196</guid><description><![CDATA[感觉象anytao的原文哦<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">lsjwzh</a> 2009-02-24 17:44 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460196#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>re: .net中非托管资源如何清理</title><link>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460188</link><dc:creator>释放托管资源</dc:creator><author>释放托管资源</author><pubDate>Tue, 24 Feb 2009 09:37:47 GMT</pubDate><guid>http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460188</guid><description><![CDATA[                if(isDisposing)<br/><br/>                {<br/><br/>                    //释放托管资源<br/><br/>                }<br/>请问如何释放托管资源<br><br><div align=right><a style="text-decoration:none;" href="http://www.cnblogs.com/pzmg/" target="_blank">释放托管资源</a> 2009-02-24 17:37 <a href="http://www.cnblogs.com/pzmg/archive/2009/02/24/1397312.html#1460188#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>
