销毁物体。 [英] Destroying objects.

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

问题描述

您好,


我有多个对象的引用。是否有可能使用其中一个引用销毁

对象,并将其余部分设置为Nothing?


Dim objA as New A
Dim objAR As A

objAR = objA

objA = Nothing

REM现在物体还活着。


Dim objA as New A

Dim objAR As A

KILL(objA)

如果objAR是Nothing然后blnGreat = True


谢谢。

Hello,

I have multiple references to an object. Is it possible to destroy the
object using one of the references, and setting the rest of them to Nothing?

Dim objA as New A
Dim objAR As A
objAR = objA
objA = Nothing
REM Now the object is still alive.

Dim objA as New A
Dim objAR As A
KILL(objA)
If objAR is Nothing then blnGreat = True

Thanks.

推荐答案

我的意思是:


Dim objA as New A

Dim objAR As A

objAR = objA

KILL(objA)

如果objAR为Nothing,则blnGreat = True


What I meant was:

Dim objA as New A
Dim objAR As A
objAR = objA
KILL(objA)
If objAR is Nothing then blnGreat = True



No。那是不可能的。你几乎无法控制实际销毁

对象的时间。这是垃圾收集器的工作。

你可以完全控制的是有多少引用

是一个对象。


如果你想要确定性的最终确定,那么使用IDisposable

界面并坚持相关的设计模式。


如果你'我想使用先进的技术来控制你可以使用WeakReference类的对象的生命周期。


你能解释一下你的内容吗? 我想要完成吗?


Brian


qwert写道:
No. That''s not possible. You have very little control over when an
object is actually destroyed. That''s the job of the garbage collector.
What you do have complete control over is how many references there
are to an object.

If you''re wanting deterministric finalization then use the IDisposable
interface and adhere to the associated design pattern.

If you''re wanting to use advanced techniques for controlling the
lifetime of objects you can use the WeakReference class.

Can you explain a little more about what you''re wanting to accomplish?

Brian

qwert wrote:
我的意思是:

Dim objA as New A
objAR = objA
KILL(objA)
如果objAR是Nothing那么blnGreat = True
What I meant was:

Dim objA as New A
Dim objAR As A
objAR = objA
KILL(objA)
If objAR is Nothing then blnGreat = True






我想在一个语句中将对象的所有引用设置为Nothing。

而不是将X引用设置为Nothing,I我想用一个X引用调用一个

语句,将它们全部设置为Nothing。


我对对象被销毁时不感兴趣。只要所有

引用都没有,所以垃圾收集器知道它是好的。


Brian Gideon <峰; br ********* @ yahoo.com>在消息中写道

news:11 ********************** @ g44g2000cwa.googlegr oups.com ...
I want to set all references to an object to Nothing in one statement.
Instead of setting X references to Nothing, I would like to call one
statement with one of the X references, setting them all to Nothing.

I''m not interested in when the object is destroyed. As long as all the
references are Nothing so the garbage collector knows it''s good to go.

"Brian Gideon" <br*********@yahoo.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
不,那是不可能的。你几乎无法控制
对象何时被实际销毁。这是垃圾收集器的工作。
你完全可以控制的是对象有多少引用。

如果你想要的话确定性终结然后使用IDisposable
界面并遵守相关的设计模式。

如果你想使用先进的技术来控制对象的生命周期你可以使用WeakReference类。

你能解释一下你想要完成什么吗?

Brian

qwert写道:
No. That''s not possible. You have very little control over when an
object is actually destroyed. That''s the job of the garbage collector.
What you do have complete control over is how many references there
are to an object.

If you''re wanting deterministric finalization then use the IDisposable
interface and adhere to the associated design pattern.

If you''re wanting to use advanced techniques for controlling the
lifetime of objects you can use the WeakReference class.

Can you explain a little more about what you''re wanting to accomplish?

Brian

qwert wrote:
我的意思是:

Dim objA as New A
Dim objAR As A
objAR = objA
KILL(objA)
如果objAR为Nothing,则blnGreat = True
What I meant was:

Dim objA as New A
Dim objAR As A
objAR = objA
KILL(objA)
If objAR is Nothing then blnGreat = True



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

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