堆栈与堆 [英] Stack vs heap

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

问题描述

DataSet ds = new DataSet()

堆栈中的变量(指针)''ds''和堆中分配的数据集对象


谢谢

Benny

DataSet ds = new DataSet()

Is the variable (pointer) ''ds'' in the stack and the dataset object being pointed allocated in the heap

Thanks
Benny

推荐答案

是的,DataSet对象驻留在堆中并且''指针''在堆栈上

如果你不保留那个指针(作为方法返回值)指针将会丢失
因此导致GC的对象集合


" Benny" <一个******* @ discussions.microsoft.com>在消息中写道

news:90 ********************************** @ microsof t.com ...
yes, DataSet object resides in the heap and ''pointer'' is on the stack
if you wont preserve that pointer (as method return value) the pointer will
be lost thus leading to DataSet object collection by GC

"Benny" <an*******@discussions.microsoft.com> wrote in message
news:90**********************************@microsof t.com...
DataSet ds = new DataSet();

堆栈中的变量(指针)''ds''和数据集对象是
指向堆中分配了什么?
谢谢,
Benny
DataSet ds = new DataSet();

Is the variable (pointer) ''ds'' in the stack and the dataset object being pointed allocated in the heap?
Thanks,
Benny



Benny< an ******* @ discussions.microsoft.com>写道:
Benny <an*******@discussions.microsoft.com> wrote:
DataSet ds = new DataSet();

堆栈中的变量(指针)''ds''和指向的数据集对象是什么?在堆中分配?
DataSet ds = new DataSet();

Is the variable (pointer) ''ds'' in the stack and the dataset object being
pointed allocated in the heap?




DataSet本身肯定在堆上。如果ds是方法中的局部变量

,它就在堆栈中。如果它是一个类或实例

变量,它也在堆上。


参见 http://www.pobox.com/~skeet/csharp/memory.html 了解更多

信息。


-

Jon Skeet - < sk *** @ pobox.com>
< a rel =nofollowhref =http://www.pobox.com/~skeettarget =_ blank> http://www.pobox.com/~skeet

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



The DataSet itself is definitely on the heap. If ds is a local variable
within a method, it''s on the stack. If it''s a class or instance
variable, it''s on the heap too.

See http://www.pobox.com/~skeet/csharp/memory.html for more
information.

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




" Vadym Stetsyak" < PD **** @ ukr.net>在消息中写道

news:e2 ************** @ TK2MSFTNGP11.phx.gbl ...

"Vadym Stetsyak" <pd****@ukr.net> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl...
是的,DataSet对象驻留在堆中,''指针''在堆栈上
如果你不保留该指针(作为方法返回值),指针
将丢失,从而导致GC收集DataSet对象
yes, DataSet object resides in the heap and ''pointer'' is on the stack
if you wont preserve that pointer (as method return value) the pointer will be lost thus leading to DataSet object collection by GC




只需注意引用可以通过其他方式保存,例如

将其存储为类范围字段。


-

Miha Markic [MVP C#] - RightHand .NET咨询&软件开发

miha at rthand com
www.rthand.com


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

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