惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Spread Privacy
Spread Privacy
P
Palo Alto Networks Blog
P
Proofpoint News Feed
AI
AI
Help Net Security
Help Net Security
S
Securelist
T
Troy Hunt's Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cisco Blogs
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
Vercel News
Vercel News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
S
Security Affairs
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
T
Tenable Blog
H
Help Net Security
NISL@THU
NISL@THU
F
Fortinet All Blogs
博客园_首页
G
GRAHAM CLULEY
L
LINUX DO - 最新话题
P
Privacy International News Feed
G
Google Developers Blog
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
The Register - Security
The Register - Security
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
Forbes - Security
Forbes - Security
S
Secure Thoughts
Simon Willison's Weblog
Simon Willison's Weblog
D
Docker
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
L
Lohrmann on Cybersecurity
T
Tailwind CSS Blog

博客园 - 一个春天

用ASP.NET 2.0实现AJAX风格的Web开发 Web2.0时代,RSS你会用了吗? web2.0开源代码 Web 2.0 编程思想:16条法则 Web2.0简介 解读Web 2.0流行词 什么是RSS? Web 2.0学习指南 什么是Web 2.0 biztalk中调用.NET类 C#创建快捷方式 获得Windows中系统特殊文件夹的位置 ADO.NET中连接池状态的跟踪 NET Framework的安装 DataGrid常见问题 DataGrid列宽度设置 User Control事件无法触发? ASP.NET中动态创建DataGrid的模板列 关于ASP.NET程序的发布
Dispose模式
一个春天 · 2004-05-19 · via 博客园 - 一个春天

       早就听说.net有了”垃圾收集器”,有了这个东东,程序员可以不再关心内存回收的问题了。但是在Delphi中已经养成了顺手清理对象的习惯,所以到了真的用.net来开发的时候不是非常适应,不把自己创建的对象清除掉,心里总有点慌慌的。
   后来想想,“垃圾收集器”相当于清洁工,定期来打扫卫生。但是如果我在产生垃圾(比如喝水的纸杯)的同时顺手就清理掉,不是更舒服?效率更高?
天好好研究了一番,觉得这篇文章写得不错:似乎同时也验证了我的想法。
http://www.eqccd.com/ServiceSupport/view.asp?kind=13&id=182
里边这样说:
*1.程序员们啊,千万不要忘记调用Dispose()方法! (如果有的话 ^_^)
*2.万一忘记,不要着急...还有救!!! 因为还有"垃圾回收器"帮我们自动调用析构方法!

这篇文章似乎也是这个意思:
http://www.fawcette.com/china/XmlFile.aspx?ID=132&page=1 
这是其中的一段话,似乎是翻译的文章,读起来有点拗口:
        通过使用Dispose模式可以适当地释放非内存资源,比如数据库连接、Win32 interop组件和操作系统的句柄。你不要指望垃圾收集器能够立即将资源释放掉,因为垃圾收集器是由于管制堆(Managed Heap)的内存紧张时才触发的。你可以快速消耗掉例如数据库连接等少量资源,但会给程序的扩展性造成副面影响。在不必要的时候不能实现Dispose模式,因为它可能会增加系统开销,而这在很多情况下是可以避免的。

原来这个问题早就已经有人专门讨论过了:
http://ms.mblogger.cn/rustle/posts/2471.aspx
讨论的主角主要是@蝈蝈俊,@Meyer,@Rustle
顺便帮他们总结一下讨论的结果:不正确的还请几个大侠指点:
1.在类的Finalize方法不要调用Connection的Close方法
2.可以在类的Dispose或者Close方法中调用Connection的Close方法,及时把Connection放回缓冲池

联想:
如果类中创建了比如DataSet,DataCommand,DataAdapter,如果没有释放,也应该在类的Dispose或者Close方法中释放吧?