关于IDispose的问题 [英] Question about IDispose

查看:64
本文介绍了关于IDispose的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用using构造,退出范围调用dispose对所述对象。但是

在连接池场景中会发生什么?运行时是否足够智能

意识到正在使用对象池,因此它不会调用dispose和

而是标记对象类似于close()所做的汇集在

效果。或者它真的继续并关闭对象?如果是的话,

那么它是不是在规避对象池?有人知道吗?


我问,因为我经常使用using构造而不是调用close,但

我想知道如果我将费用引入等式中处置不是像我想象的那样有效地行事。


??


-

问候,

Alvin Bruney [ASP.NET MVP]

得到花絮?在此处获取...
http://tinyurl.com/3he3b

解决方案



" Alvin Bruney [MVP]" <蒸汽邮局的蒸汽>在消息中写道

新闻:**************** @ tk2msftngp13.phx.gbl ...

with using构造,退出范围调用处理所述对象。
但是
在连接池方案中会发生什么?运行时是否足够聪明
意识到正在使用对象池,因此它不会调用dispose
而是标记对象类似于close()所做的汇集是有效的。或者它真的继续并关闭对象?如果确实如此,
那么它是不是在绕过对象汇集?有人知道吗?

我问,因为我经常使用using构造而不是调用close,
但是我想知道如果处置是<我是否在费用中引入费用没有像我想象的那样有效地表现。


使用应该盲目地调用Dispose。由对象实现者

来编写一个与池系统一起正常工作的Dispose方法。你需要分析相关课程的行为。


??

-
问候,Alvin Bruney [ASP.NET MVP]
有花絮?在此处获取...
http://tinyurl.com/3he3b



那么在网页中究竟是什么意思(windows窗体没有&b
护理关于汇集大部分是因为它本身并不昂贵。

使用(MySQLConnection cn = new MySQLConnection(Global._connString3))

>
{


}


我根本不同意这个实现。因为它本身就是昂贵的代价是安全的代价。它是安全性还是性能蛋糕?这完全否定了连接池的好处。它应该附带一个免责声明,因为我总是认为它具有某种智能工作




给我一个很好的理由为什么dispose不应该有关于对象池的内置智能

。我需要这种智能用于Web开发

,因为对象创建本质上是昂贵的。对于

windows程序来说没关系。我怀疑网络程序是一个想法。这是错误的

我对发生的事情的看法有限。

-

问候,

Alvin Bruney [ASP.NET MVP]

有花絮吗?在此处获取...
http://tinyurl.com/3he3b

Daniel O''Connell [C#MVP]" < onyxkirx @ - NOSPAM--comcast.net>写在

消息新闻:Oo ****************** @ tk2msftngp13.phx.gbl ...


Alvin Bruney [MVP]" <蒸汽邮局的蒸汽>在消息中写道
新闻:**************** @tk2msftngp13.phx.gbl ...

with using构造,退出范围调用处理所述对象。
但是
在连接池方案中会发生什么?运行时是否足够聪明
意识到正在使用对象池,因此它不会调用dispose
而是标记对象类似于close()所做的汇集是有效的。或者它真的继续并关闭对象?如果确实如此,
那么它是不是在绕过对象汇集?有人知道吗?

我问,因为我经常使用using构造而不是调用close,
但是我想知道如果处置是<我是否在费用中引入费用没有像我想象的那样有效地表现。

使用应该盲目地调用Dispose。由对象



实现者来编写一个与池系统一起正常工作的Dispose方法。您将需要分析相关课程的行为。

??

-
问候,Alvin Bruney [ASP.NET MVP]
有花絮?在此处获取...
http://tinyurl.com/3he3b




<" Alvin Bruney [MVP]" <蒸汽邮局的蒸汽>>写道:

那么在网页中究竟是什么意思(windows窗体并不关心大部分的汇集因为它本身并不昂贵) )。
使用(MySQLConnection cn = new MySQLConnection(Global._connString3))

{

}

我不同意有了这个实现。因为它本身就是昂贵而牺牲了安全性。它是安全性还是性能蛋糕?这完全否定了连接池的好处。它应该附带一个免责声明,因为我总是认为它有一定的智能。

给我一个很好的理由为什么处理不应该有一些内置智慧
关于对象池。


因为IDisposable是一个非常通用的界面,所以不应该参考

。这是一个可怕的,可怕的想法,因为对于了解数据库而言,这可能是一般的知识。它将知识

放在完全错误的地方。


智能的*右*位置在MySQLConnection中,它可以实现IDisposable,但是它希望。

我需要这种智能用于Web开发
因为对象创建本质上是昂贵的。对于
windows程序来说没关系。我怀疑网络程序是一个想法。这是错误的
在我对正在发生的事情的有限看法中。




你确定*使用上述模式实际上忽略了

连接池?不要以为在MySQLConnection实例与

数据库的实际连接之间存在直接关联




-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复群组,请不要给我发邮件


with the using construct, exit from scope calls dispose on said object. But
what happens in a connection pooling scenario? Is the run-time smart enough
to realize that Object Pooling is being used so it will not call dispose and
instead flag the object similar to what close() does when pooling is in
effect. Or does it really go ahead and shut down the object? If it does,
then isn''t it circumventing the object pooling? Does anybody know?

I ask because I often use the using construct instead of calling close, but
I wonder if I am introducing expense into the equation if the dispose is not
behaving efficiently like I assumed.

??

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b

解决方案


"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:Of****************@tk2msftngp13.phx.gbl...

with the using construct, exit from scope calls dispose on said object.
But
what happens in a connection pooling scenario? Is the run-time smart
enough
to realize that Object Pooling is being used so it will not call dispose
and
instead flag the object similar to what close() does when pooling is in
effect. Or does it really go ahead and shut down the object? If it does,
then isn''t it circumventing the object pooling? Does anybody know?

I ask because I often use the using construct instead of calling close,
but
I wonder if I am introducing expense into the equation if the dispose is
not
behaving efficiently like I assumed.

Using should blindly call Dispose. It would be up to the object implementer
to write a Dispose method that works properly with the pooling system. You
will have to analyze the behaviour of the class in question.

??

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b



so what exactly is the point of this in a web page (windows forms doesn''t
care about pooling for the most part because it is not inherently
expensive).
using(MySQLConnection cn = new MySQLConnection (Global._connString3))

{

}

I am not in agreement with this implementation at all. Because it is
inherently costly at the expense of being safe. Is it an either safety or
performance cake? That totally negates the benefit of connection pooling. It
should come with a disclaimer as well because I always assumed it worked
with some sort of intelligence.

Give me a good reason why dispose should not have some built-in intelligence
with regard to object pooling. I need this intelligence for web development
because object creation is inherently expensive. It doesn''t matter for
windows program. I suspuct web program was an after thought. This is wrong
in my limited view of what is happening.
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Daniel O''Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:Oo******************@tk2msftngp13.phx.gbl...


"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:Of****************@tk2msftngp13.phx.gbl...

with the using construct, exit from scope calls dispose on said object.
But
what happens in a connection pooling scenario? Is the run-time smart
enough
to realize that Object Pooling is being used so it will not call dispose
and
instead flag the object similar to what close() does when pooling is in
effect. Or does it really go ahead and shut down the object? If it does,
then isn''t it circumventing the object pooling? Does anybody know?

I ask because I often use the using construct instead of calling close,
but
I wonder if I am introducing expense into the equation if the dispose is
not
behaving efficiently like I assumed.

Using should blindly call Dispose. It would be up to the object


implementer to write a Dispose method that works properly with the pooling system. You
will have to analyze the behaviour of the class in question.

??

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b




<"Alvin Bruney [MVP]" <vapor at steaming post office>> wrote:

so what exactly is the point of this in a web page (windows forms doesn''t
care about pooling for the most part because it is not inherently
expensive).
using(MySQLConnection cn = new MySQLConnection (Global._connString3))

{

}

I am not in agreement with this implementation at all. Because it is
inherently costly at the expense of being safe. Is it an either safety or
performance cake? That totally negates the benefit of connection pooling. It
should come with a disclaimer as well because I always assumed it worked
with some sort of intelligence.

Give me a good reason why dispose should not have some built-in intelligence
with regard to object pooling.
Because IDisposable is a very general interface, and shouldn''t refer to
anything specific. It''s a horrible, horrible idea for something as
general as IDisposable to know about databases - it''s putting knowledge
in entirely the wrong place.

The *right* place for the "smarts" is in MySQLConnection, which can
implement IDisposable however it wishes.
I need this intelligence for web development
because object creation is inherently expensive. It doesn''t matter for
windows program. I suspuct web program was an after thought. This is wrong
in my limited view of what is happening.



Are you *sure* that using the above pattern is actually ignoring
connection pooling? Don''t assume that there''s a direct correlation
between MySQLConnection instances and actual connections to the
database.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于关于IDispose的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆