再次配置! [英] Dispose Again!

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

问题描述

好的,我正在尝试根据此新闻组的建议处理我创建的具有处置

方法的每个对象。但是,我不知道如何处理在方法调用中创建的以下对象。


dim myvar作为新对象1

object1.dosomethingmethod(new object2)


请注意,对象2有一个dispose方法,但除非我支付
,否则我该怎么处理它执行以下操作:


dim myvar作为新对象1

dim mydisposableobject作为新对象2

object1.dosomethingmethod(mydisposableobject)

myotherobject.Dispose

-

Dennis in Houston

解决方案

< blockquote>你的第二段代码是你的解决方案。


Dennis <德**** @ discussions.microsoft.com>在留言中写道

新闻:1F ********************************** @ microsof t.com ...

好的,我正在尝试根据此新闻组的建议处理我创建的具有处置方法的每个对象。但是,我不知道如何处理在方法调用中创建的以下对象。

将myvar作为新对象调用1
object1.dosomethingmethod(new object2 )

请注意,对象2有一个处理方法但我该如何处理它,除非我执行以下操作:

将myvar作为新的object1
dim mydisposableobject as new object 2
object1.dosomethingmethod(mydisposableobject)
myotherobject.Dispose

-
Dennis in Houston



我是这么认为的。我在MSDN中看到很多使用第一个代码的例子,所以我猜他们不会丢弃这些对象并把它留给GC。


Scott M.写道:

你的第二段代码是你的解决方案。

丹尼斯 <德**** @ discussions.microsoft.com>在消息中写道
新闻:1F ********************************** @ microsof t.com。 ..

好的,我正在尝试根据这个新闻组的建议处理我创建的具有处置方法的每个对象。但是,我不知道如何处理在方法调用中创建的以下对象。

将myvar作为新对象调用1
object1.dosomethingmethod(new object2 )

请注意,对象2有一个处理方法但我该如何处理它,除非我执行以下操作:

将myvar作为新的object1
dim mydisposableobject as new object 2
object1.dosomethingmethod(mydisposableobject)
myotherobject.Dispose

-
Dennis in Houston




>> MDSN中的很多例子。


是的......邋懒懒惰的经常出错..


我想如果你做了很多那样的事情你可以尝试将

对象转换成IDisposable并处理掉它它成功了。


-

鲍勃鲍威尔[MVP]

Visual C#,System.Drawing


在Windows窗体提示和技巧中查找优秀的Windows窗体文章
http://www.bobpowell.net/tipstricks.htm


用GDI + FAQ回答那些GDI +问题
http://www.bobpowell.net/faqmain.htm


所有新文章都提供C#和VB.NET代码。

订阅所提供的RSS提要,绝不会错过任何新文章。


Dennis <德**** @ discussions.microsoft.com>在留言中写道

新闻:FF ********************************** @ microsof t.com ...

我是这么认为的。我在MSDN中看到许多使用第一个代码的例子,所以我猜他们不会丢弃这些对象并将它留给GC。

Scott M.写道:

你的第二段代码是你的解决方案。

丹尼斯 <德**** @ discussions.microsoft.com>在消息中写道
新闻:1F ********************************** @ microsof t.com。 ..

>好的,我正在尝试处理我创建的每个具有
>的对象。处理
>基于该新闻组的建议的方法。但是,我不确定
>到
>处理在方法调用中创建的以下对象。
>
>昏暗的myvar作为新对象1
> object1.dosomethingmethod(new object2)
>
>请注意,对象2有一个配置方法,但我该如何处理它
>除非
>我
>执行以下操作:
>
>昏暗的myvar作为新对象1
>昏暗的mydisposableobject作为新对象2
> object1.dosomethingmethod(mydisposableobject)
> myotherobject.Dispose
>
>
> -
>休斯顿的丹尼斯




Ok, I''m trying to dispose of every object that I create that has a dispose
method based on advice from this newsgroup. However, I''m not sure how to
dispose of the following object that was created inside a method call.

dim myvar as new object1
object1.dosomethingmethod(new object2)

Note that object 2 has a dispose method but how do I dispose of it unless I
do the following:

dim myvar as new object1
dim mydisposableobject as new object 2
object1.dosomethingmethod(mydisposableobject )
myotherobject.Dispose
--
Dennis in Houston

解决方案

Your second bit of code is your solution.

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...

Ok, I''m trying to dispose of every object that I create that has a dispose
method based on advice from this newsgroup. However, I''m not sure how to
dispose of the following object that was created inside a method call.

dim myvar as new object1
object1.dosomethingmethod(new object2)

Note that object 2 has a dispose method but how do I dispose of it unless
I
do the following:

dim myvar as new object1
dim mydisposableobject as new object 2
object1.dosomethingmethod(mydisposableobject )
myotherobject.Dispose
--
Dennis in Houston



I thought so. I see lots of examples in MSDN that use the first code so I
guess they don''t dispose of the objects and leave it to the GC.

"Scott M." wrote:

Your second bit of code is your solution.

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...

Ok, I''m trying to dispose of every object that I create that has a dispose
method based on advice from this newsgroup. However, I''m not sure how to
dispose of the following object that was created inside a method call.

dim myvar as new object1
object1.dosomethingmethod(new object2)

Note that object 2 has a dispose method but how do I dispose of it unless
I
do the following:

dim myvar as new object1
dim mydisposableobject as new object 2
object1.dosomethingmethod(mydisposableobject )
myotherobject.Dispose
--
Dennis in Houston




>>lots of examples in MDSN.

Yes.. sloppy lazy and often wrong..

I guess if you do a lot of that sort of thing you can try to convert the
object to IDisposable and dispose of it if it succeeds.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...

I thought so. I see lots of examples in MSDN that use the first code so I
guess they don''t dispose of the objects and leave it to the GC.

"Scott M." wrote:

Your second bit of code is your solution.

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...

> Ok, I''m trying to dispose of every object that I create that has a
> dispose
> method based on advice from this newsgroup. However, I''m not sure how
> to
> dispose of the following object that was created inside a method call.
>
> dim myvar as new object1
> object1.dosomethingmethod(new object2)
>
> Note that object 2 has a dispose method but how do I dispose of it
> unless
> I
> do the following:
>
> dim myvar as new object1
> dim mydisposableobject as new object 2
> object1.dosomethingmethod(mydisposableobject )
> myotherobject.Dispose
>
>
> --
> Dennis in Houston




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

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