如何销毁数组 [英] How to destroy arrays

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

问题描述




我在集合中创建了一个对象数组。我想知道是否有一种方法来销毁阵列以释放内存空间?

或者它们是自动销毁并通过.Net框架收集的内容?


Sarfraz

Hi,

I have created an array of Objects in a collection. I was wondering is there
a way to destroy the array to free up the space in the memory ? or they are
automatically destroyed and garbagge collected by .Net framework?

Sarfraz

推荐答案

.NET中的所有内容都是一种类型(引用或值类型)。所有类型

由垃圾收集器管理。没有必要释放内存

,因为这是GC的目的。但是在某些情况下,当您可能希望有问题的对象立即超出范围时,

而不是等待程序结束。在这种情况下,你可以使

对象=无。

Sarfraz Hooda < SH **** @ iqueri.com>写在消息

新闻:Od ************** @ TK2MSFTNGP09.phx.gbl ...
Everything in .NET is a type (either reference or value types). All types
are managed by the Garbage Collector. There is no need to "free up memory"
as this is the purpose of the GC. There are certain circumstances though,
when you may want the object in question to fall out of scope immediately,
rather than waiting for the end of a procedure. In this case you could make
the object = Nothing.
"Sarfraz Hooda" <sh****@iqueri.com> wrote in message
news:Od**************@TK2MSFTNGP09.phx.gbl...

我在一个集合中创建了一个对象数组。我想知道
有没有办法销毁数组以释放内存中的空间?或者他们
会被.Net框架自动销毁和收集?

Sarfraz
Hi,

I have created an array of Objects in a collection. I was wondering is there a way to destroy the array to free up the space in the memory ? or they are automatically destroyed and garbagge collected by .Net framework?

Sarfraz



Scott M.< s-*** @ nospam.nospam>写道:
Scott M. <s-***@nospam.nospam> wrote:
.NET中的所有内容都是一种类型(引用或值类型)。所有类型都由垃圾收集器管理。没有必要释放内存
因为这是GC的目的。但是在某些情况下,
当您可能希望有问题的对象立即超出范围时,而不是等待程序结束。在这种情况下,您可以使对象=无。
Everything in .NET is a type (either reference or value types). All types
are managed by the Garbage Collector. There is no need to "free up memory"
as this is the purpose of the GC. There are certain circumstances though,
when you may want the object in question to fall out of scope immediately,
rather than waiting for the end of a procedure. In this case you could make
the object = Nothing.




通常,这是不必要的,但是,垃圾收集器可以告诉
当变量最后在IL中使用时
。除非你处于一个特殊的特殊情况下(例如,在

长循环的第一次迭代中使用变量,而不是之后),它是'最好不要弄乱你的代码

将变量设置为null / Nothing。


-

Jon Skeet - < sk ***@pobox.com>
http://www.pobox.com /〜双向飞碟

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



Usually that''s unnecessary, however, as the garbage collector can tell
when a variable is last used in the IL. Unless you''re in a particularly
special case (eg where a variable is used in the first iteration of a
long loop, and not thereafter) it''s best not to clutter up your code
setting variables to null/Nothing.

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


Jon Jon,


也许这是更高的英语;但是你能告诉我你的消息在哪里吗?
不同于Scott的消息?


我发现Scotts的消息很清楚我完全赞同他的方式

他写的。


Cor
Hi Jon,

Maybe this is higher English; however can you tell me where your message is
different from that from Scott?

I found Scotts message very clear and I agree completely with him in the way
he wrote it.

Cor
.NET中的所有东西都是类型(引用或值类型)。所有
类型都由垃圾收集器管理。没有必要释放
内存。因为这是GC的目的。在某些情况下,当你可能希望有问题的对象立即超出范围
而不是等待程序结束时,某些情况是
。在这种情况下,您可以
使对象= Nothing。
Everything in .NET is a type (either reference or value types). All types are managed by the Garbage Collector. There is no need to "free up memory" as this is the purpose of the GC. There are certain circumstances though, when you may want the object in question to fall out of scope immediately, rather than waiting for the end of a procedure. In this case you could make the object = Nothing.



通常这是不必要的,因为垃圾收集器可以告诉
何时变量是最后用于IL。除非你处于一个特殊的特殊情况(例如,在长循环的第一次迭代中使用变量,而不是之后),否则最好不要混淆代码
将变量设置为null / Nothing。



Usually that''s unnecessary, however, as the garbage collector can tell
when a variable is last used in the IL. Unless you''re in a particularly
special case (eg where a variable is used in the first iteration of a
long loop, and not thereafter) it''s best not to clutter up your code
setting variables to null/Nothing.



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

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