在.NET中实例化一个类 [英] Instantiating a class in.NET

查看:58
本文介绍了在.NET中实例化一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在.Net中有一个类,我在我的代码中实例化了

在我的一个aspx页面后面。


当我完成实例时,什么是最好的

将其从内存中取出的方法。我应该将它设置为

什么或者我可以处理它吗?


谢谢,

Carl。

解决方案

将它设置为空。

你不应该需要任何花哨的处理东西,除非班级是开着的

非常宝贵的资源。


-

我希望这会有所帮助,

Steve C. Orr,MCSD
http://Steve.Orr.net

"卡尔" < CA ** @ nospam.com>在消息中写道

news:92 **************************** @ phx.gbl ... < blockquote class =post_quotes>

我在.Net中有一个类,我在我的代码中实例化了
后面的一个aspx页面。

当我完成实例时,最好的方法是将它从内存中取出。我应该把它设置为
什么或者我可以处理它吗?

谢谢,
Carl。



< blockquote>是的,但是整洁都没有伤害。

在VB6中你理论上也不需要清理东西,但

现实有时是自动清理工作并不是很好。

它声称。

它似乎在.NET中表现得更好但是我仍然不确定我是否相信它100%。

最好是安全而不是抱歉并清理自己的混乱。


-

我希望这有助于,

Steve C. Orr,MCSD
http://史蒂夫.Orr.net

" Kevin Spencer" <柯*** @ takempis.com>在留言中写道

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

它没有必要将它设置为空,也没有任何效果(如COM)。一旦
超出范围,该对象就会出现垃圾收集。

-
HTH,

Kevin Spencer Microsoft MVP
.Net Developer
http://www.takempis.com
复杂的事情由许多简单的东西组成。

Steve C. Orr,MCSD <圣*** @ Orr.net>在消息中写道
新闻:uW ************** @ TK2MSFTNGP11.phx.gbl ...

设置它等于什么。
你不应该需要任何花哨的处理东西,除非班级持有


打开

非常有价值的资源。

- 我希望这有帮助,
Steve C. Orr,MCSD
http:// Steve.Orr.net

" Carl" < CA ** @ nospam.com>在消息中写道
新闻:92 **************************** @ phx.gbl ...



我在.Net上有一个课程,我在我的代码中实例化我的aspx页面后面。

当我完成对于实例,最好的方法是将它从内存中取出来。我应该把它设置为
什么或者我可以处理它吗?

谢谢,
Carl。





史蒂夫,


为什么甚至打扰将引用设置为Nothing?这不是COM - 它不会

减少参考计数。


-

John Saunders

互联网工程师
jo *********** @ surfcontrol.com

" Steve C. Orr,MCSD" <圣*** @ Orr.net>在消息中写道

新闻:uW ************** @ TK2MSFTNGP11.phx.gbl ...

将它设为等于零。
你不应该需要任何花哨的处理东西,除非班级持有
开放异常宝贵的资源。

-
我希望这有帮助,
Steve C. Orr,MCSD
http://Steve.Orr.net

" Carl" < CA ** @ nospam.com>在消息中写道
新闻:92 **************************** @ phx.gbl ...



我在.Net上有一个课程,我在我的代码中实例化我的aspx页面后面。

当我完成对于实例,最好的方法是将它从内存中取出来。我应该把它设置为
什么或者我可以处理它吗?

谢谢,
Carl。




Hi,

I have a class in .Net which I instantiate in my code
behind on one of my aspx pages.

When I am finished with the instance, what is teh best
method of taking it out of memory. Should I set it to
nothing or can I dispose of it?

Thanks,
Carl.

解决方案

Set it equal to nothing.
You shouldn''t need any fancy disposal stuff unless the class is holding open
unusually valuable resources.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Carl" <ca**@nospam.com> wrote in message
news:92****************************@phx.gbl...

Hi,

I have a class in .Net which I instantiate in my code
behind on one of my aspx pages.

When I am finished with the instance, what is teh best
method of taking it out of memory. Should I set it to
nothing or can I dispose of it?

Thanks,
Carl.



True, but it never hurts to be tidy.
In VB6 you theoretically didn''t need to clean things up either, but the
reality was that sometimes the automatic cleanup didn''t work quite as well
as it claimed.
It seems to behave better in .NET but I''m still not sure if I trust it 100%.
Better to be safe than sorry and clean up your own messes.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...

It isn''t necessary to set it to nothing, nor does it have any effect to do
so (unlike COM). The object will be up for Garbage Collection as soon as it passes out of scope.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uW**************@TK2MSFTNGP11.phx.gbl...

Set it equal to nothing.
You shouldn''t need any fancy disposal stuff unless the class is holding


open

unusually valuable resources.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Carl" <ca**@nospam.com> wrote in message
news:92****************************@phx.gbl...

Hi,

I have a class in .Net which I instantiate in my code
behind on one of my aspx pages.

When I am finished with the instance, what is teh best
method of taking it out of memory. Should I set it to
nothing or can I dispose of it?

Thanks,
Carl.





Steve,

Why even bother setting the reference to Nothing? This isn''t COM - it won''t
decrement the reference count.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:uW**************@TK2MSFTNGP11.phx.gbl...

Set it equal to nothing.
You shouldn''t need any fancy disposal stuff unless the class is holding open unusually valuable resources.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Carl" <ca**@nospam.com> wrote in message
news:92****************************@phx.gbl...

Hi,

I have a class in .Net which I instantiate in my code
behind on one of my aspx pages.

When I am finished with the instance, what is teh best
method of taking it out of memory. Should I set it to
nothing or can I dispose of it?

Thanks,
Carl.




这篇关于在.NET中实例化一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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