了解Dispose方法和数据集? [英] Understanding the Dispose method and datasets?

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

问题描述

数据集是否自动存储在内存中?

dispose()方法是否会自动处理代码中的数据集

以下?


我是否必须从内存中处理数据集,或者数据集是否在不使用时处理了
本身?


我知道我可以使用clear方法,但是只清除

数据集中的数据不能一起处理数据集吗?


*****代码例如

公共重载函数RetrievePersonalization(ByVal AccountID为

整数)As DataRow


Dim parameters As SqlParameter()= {新的SqlParameter(@ AccountID",

SqlDbType.Int,4)}

参数(0).Value = AccountID


Dim Account As DataSet

尝试

账户= RunProcedure(GetStudentPersonalization,参数,账户)

退货账户。表(0)。行(0)

Account.Dispose()


最后

如果不是账户什么都没有那么

账户。分配()

结束如果

结束尝试


结束功能

解决方案

嗨Leon:


就内存而言,你不必处理任何对象。

CLR管理内存并定期回收未使用的内存

与垃圾收集器。这包括DataSet和

DataSet中的数据。调用Dispose并不急于这个过程。


Dispose用于非托管资源,如文件句柄和数据库

连接。经验法则是在实现IDisposable的任何和每个
对象上调用Dispose。不幸的是,DataSet

继承自MarshalByValueComponent,它为DataSet提供了一个

Dispose方法。在实践中我们很少处理DataSet因为它没有提供什么好处,而且DataSet经常会出现在远程处理和

缓存场景中,你不知道什么时候所有的客户端实际上是用数据集完成的



-

Scott
http://www.OdeToCode.com/blogs/scott/

周五,2004年11月12日09:56:49 -0600,Leon < VN ***** @ msn.com>写道:

数据集是否自动存储在内存中?

dispose()方法是否自动处理下面的代码中的数据集?

我是否必须从内存中处理数据集,或者数据集是否在不使用时自行处理?

我知道我可以使用clear方法,但是只清除
数据集中的数据而不是一起处理数据集吗?

*****代码例。
公共过载函数RetrievePersonalization(ByVal AccountID As
整数)As DataRow

Dim参数As SqlParameter()= {New SqlParameter(" @ AccountID",
SqlDbType.Int,4)}
参数(0)。值=帐户ID

作为数据集的暗淡帐户
尝试
帐户= RunProcedure(GetStudentPersonalization,参数,帐户)
返回帐户。表(0 ).Rows(0)
Account.Dispose()

最后
如果Not Account is Nothing那么
Account.Dispose()
结束功能




你是对的谢谢,但是..

是一个管理或非管理资源的arraylist?


" Scott Allen" <位掩码@ [NOSPAM] .fred.net>在消息中写道

新闻:h1 ******************************** @ 4ax.com ...

嗨Leon:

就内存而言,您不必处置任何对象。
CLR管理内存并定期回收未使用的内存
与垃圾收集器。这包括DataSet和数据集中的数据。调用Dispose并不急于这个过程。

Dispose用于非托管资源,如文件句柄和数据库
连接。经验法则是在实现IDisposable的任何和每个
对象上调用Dispose。不幸的是,DataSet
继承自MarshalByValueComponent,它为DataSet提供了一个Dispose方法。在实践中,我们很少处理DataSet,因为它几乎没有带来任何好处,而DataSet通常最终会出现在远程处理和缓存场景中,你不知道所有客户端何时完成了数据集

-
http://www.OdeToCode.com/blogs/scott/

周五,2004年11月12日09:56:49 -0600,Leon < VN ***** @ msn.com>写道:

数据集是否自动存储在内存中?

dispose()方法是否自动处理下面的代码中的数据集?

我是否必须从内存中处理数据集,或者数据集是否在不使用时自行处理?

我知道我可以使用clear方法,但是只清除
数据集中的数据而不是一起处理数据集吗?

*****代码例。
公共过载函数RetrievePersonalization(ByVal AccountID As
整数)As DataRow

Dim参数As SqlParameter()= {New SqlParameter(" @ AccountID",
SqlDbType.Int,4)}
参数(0)。值=帐户ID

作为数据集的暗淡帐户
尝试
帐户= RunProcedure(GetStudentPersonalization,参数,
帐户)
返回帐户.Tables(0).Rows(0)
Account.Dispose()

最后
如果Not Account is Nothing那么
Account.Dispose()
结束如果结束尝试

结束功能



内存是一个托管资源。

将管理ArrayList使用的内存。


如果ArrayList保留在任何未管理的资源上,它将实现

IDisposable(它没有)。


-

Scott
http://www.OdeToCode.com/blogs/scott/


周五,2004年11月12日10:40:43 -0600,Leon < VN ***** @ msn.com>写道:

你是对的,但是..
是一个管理或非管理资源的arraylist?

Scott Allen <位掩码@ [NOSPAM] .fred.net>在消息中写道
新闻:h1 ******************************** @ 4ax.com ..。< blockquote class =post_quotes>嗨Leon:

就内存而言,您不必处置任何对象。
CLR管理内存并定期回收未使用的内存
带垃圾收集器。这包括DataSet和数据集中的数据。调用Dispose并不急于这个过程。

Dispose用于非托管资源,如文件句柄和数据库
连接。经验法则是在实现IDisposable的任何和每个
对象上调用Dispose。不幸的是,DataSet
继承自MarshalByValueComponent,它为DataSet提供了一个Dispose方法。在实践中,我们很少处理DataSet,因为它几乎没有带来任何好处,而DataSet通常最终会出现在远程处理和缓存场景中,你不知道所有客户端何时完成了数据集

-
http://www.OdeToCode.com/blogs/scott/

周五,2004年11月12日09:56:49 -0600,Leon < VN ***** @ msn.com>写道:

数据集是否自动存储在内存中?

dispose()方法是否自动处理下面的代码中的数据集?

我是否必须从内存中处理数据集,或者数据集是否在不使用时自行处理?

我知道我可以使用clear方法,但是只清除
数据集中的数据而不是一起处理数据集吗?

*****代码例。
公共过载函数RetrievePersonalization(ByVal AccountID As
整数)As DataRow

Dim参数As SqlParameter()= {New SqlParameter(" @ AccountID",
SqlDbType.Int,4)}
参数(0)。值=帐户ID

作为数据集的暗淡帐户
尝试
帐户= RunProcedure(GetStudentPersonalization,参数,
帐户)
返回帐户.Tables(0).Rows(0)
Account.Dispose()

最后
如果Not Account is Nothing那么
Account.Dispose()
结束如果结束尝试

结束功能




Are dataset automatically stored in memory?

Does the dispose() method automatically dispose of the dataset in the code
below?

Do I have to dispose a dataset from memory or does the dataset dispose
itself when not in use?

I know I can use the clear method, but that just clear the data within
dataset not dispose of the dataset all together right?

*****Code Ex.
Public Overloads Function RetrievePersonalization(ByVal AccountID As
Integer) As DataRow

Dim parameters As SqlParameter() = { New SqlParameter("@AccountID",
SqlDbType.Int, 4)}
parameters(0).Value = AccountID

Dim Account As DataSet
Try
Account = RunProcedure( "GetStudentPersonalization", parameters, "Account")
Return Account.Tables(0).Rows(0)
Account.Dispose()

Finally
If Not Account Is Nothing Then
Account.Dispose()
End If
End Try

End Function


解决方案

Hi Leon:

As far as memory is concerned, you do not have to Dispose any object.
The CLR manages memory and will periodically reclaim unused memory
with a garbage collector. This includes the DataSet and the data in a
DataSet. Calling Dispose does not hurry this process along.

Dispose is for unmanaged resources, like file handles and database
connections. The rule of thumb is to call Dispose on any and every
object that implements IDisposable. Unfortunately, the DataSet
inherits from MarshalByValueComponent which gives the DataSet a
Dispose method. In pratice we rarely Dispose a DataSet because it
offers little benefit, and the DataSet often ends up in remoting and
caching scenarios where you don''t know when all clients are actually
done with the DataSet

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 12 Nov 2004 09:56:49 -0600, "Leon" <vn*****@msn.com> wrote:

Are dataset automatically stored in memory?

Does the dispose() method automatically dispose of the dataset in the code
below?

Do I have to dispose a dataset from memory or does the dataset dispose
itself when not in use?

I know I can use the clear method, but that just clear the data within
dataset not dispose of the dataset all together right?

*****Code Ex.
Public Overloads Function RetrievePersonalization(ByVal AccountID As
Integer) As DataRow

Dim parameters As SqlParameter() = { New SqlParameter("@AccountID",
SqlDbType.Int, 4)}
parameters(0).Value = AccountID

Dim Account As DataSet
Try
Account = RunProcedure( "GetStudentPersonalization", parameters, "Account")
Return Account.Tables(0).Rows(0)
Account.Dispose()

Finally
If Not Account Is Nothing Then
Account.Dispose()
End If
End Try

End Function




you are right thanks, but..
is an arraylist a managed or unmanaged resource?

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:h1********************************@4ax.com...

Hi Leon:

As far as memory is concerned, you do not have to Dispose any object.
The CLR manages memory and will periodically reclaim unused memory
with a garbage collector. This includes the DataSet and the data in a
DataSet. Calling Dispose does not hurry this process along.

Dispose is for unmanaged resources, like file handles and database
connections. The rule of thumb is to call Dispose on any and every
object that implements IDisposable. Unfortunately, the DataSet
inherits from MarshalByValueComponent which gives the DataSet a
Dispose method. In pratice we rarely Dispose a DataSet because it
offers little benefit, and the DataSet often ends up in remoting and
caching scenarios where you don''t know when all clients are actually
done with the DataSet

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 12 Nov 2004 09:56:49 -0600, "Leon" <vn*****@msn.com> wrote:

Are dataset automatically stored in memory?

Does the dispose() method automatically dispose of the dataset in the code
below?

Do I have to dispose a dataset from memory or does the dataset dispose
itself when not in use?

I know I can use the clear method, but that just clear the data within
dataset not dispose of the dataset all together right?

*****Code Ex.
Public Overloads Function RetrievePersonalization(ByVal AccountID As
Integer) As DataRow

Dim parameters As SqlParameter() = { New SqlParameter("@AccountID",
SqlDbType.Int, 4)}
parameters(0).Value = AccountID

Dim Account As DataSet
Try
Account = RunProcedure( "GetStudentPersonalization", parameters,
"Account")
Return Account.Tables(0).Rows(0)
Account.Dispose()

Finally
If Not Account Is Nothing Then
Account.Dispose()
End If
End Try

End Function



Memory is a managed resource.
The memory an ArrayList uses will be managed.

If the ArrayList held on to any unmanged resources, it would implement
IDisposable (which it doesn''t).

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 12 Nov 2004 10:40:43 -0600, "Leon" <vn*****@msn.com> wrote:

you are right thanks, but..
is an arraylist a managed or unmanaged resource?

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:h1********************************@4ax.com.. .

Hi Leon:

As far as memory is concerned, you do not have to Dispose any object.
The CLR manages memory and will periodically reclaim unused memory
with a garbage collector. This includes the DataSet and the data in a
DataSet. Calling Dispose does not hurry this process along.

Dispose is for unmanaged resources, like file handles and database
connections. The rule of thumb is to call Dispose on any and every
object that implements IDisposable. Unfortunately, the DataSet
inherits from MarshalByValueComponent which gives the DataSet a
Dispose method. In pratice we rarely Dispose a DataSet because it
offers little benefit, and the DataSet often ends up in remoting and
caching scenarios where you don''t know when all clients are actually
done with the DataSet

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Fri, 12 Nov 2004 09:56:49 -0600, "Leon" <vn*****@msn.com> wrote:

Are dataset automatically stored in memory?

Does the dispose() method automatically dispose of the dataset in the code
below?

Do I have to dispose a dataset from memory or does the dataset dispose
itself when not in use?

I know I can use the clear method, but that just clear the data within
dataset not dispose of the dataset all together right?

*****Code Ex.
Public Overloads Function RetrievePersonalization(ByVal AccountID As
Integer) As DataRow

Dim parameters As SqlParameter() = { New SqlParameter("@AccountID",
SqlDbType.Int, 4)}
parameters(0).Value = AccountID

Dim Account As DataSet
Try
Account = RunProcedure( "GetStudentPersonalization", parameters,
"Account")
Return Account.Tables(0).Rows(0)
Account.Dispose()

Finally
If Not Account Is Nothing Then
Account.Dispose()
End If
End Try

End Function




这篇关于了解Dispose方法和数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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