对象引用丢失,但保留的资源被保留 [英] Object references are lost but the resources held are retained
本文介绍了对象引用丢失,但保留的资源被保留的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IndentedTextWriter tw = new IndentedTextWriter(internalTW, " ");
"tw"引用的对象丢失,但此处未配置相关资源."TW"是文本编写器,其中internalTW是TextWriter
Object referenced by 'tw' is lost, but related resources are not disposed here "TW " is a text writer where internalTW is a TextWriter
OleDbConnection con = new OleDbConnection(conStr);
OleDbCommand cmd = new OleDbCommand(cmd1, con);
'cmd'引用的对象丢失,但此处未配置相关资源
object referenced by 'cmd' is lost, but related resources are not disposed here
推荐答案
尝试
using (IndentedTextWriter tw = new IndentedTextWriter(internalTW, " ")) {
// use it here
}
resp.
using (OleDbConnection con = new OleDbConnection(conStr))
using (OleDbCommand cmd = new OleDbCommand(cmd1, con)) {
// use it here
}
在 using
块的末尾,在对象上调用 Dispose()
,并且应该释放资源...
At the end of the using
block, Dispose()
is called on the objects and the resources should be freed...
这篇关于对象引用丢失,但保留的资源被保留的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文