什么时候没有比什么都好? [英] When is NOTHING better than nothing?

查看:53
本文介绍了什么时候没有比什么都好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我知道:


Dim RS As ADODB.Recordset

设置RS = CurrentProject.Connection.Execute(" EXEC" &mySPROCname)


''在这里发生各种各样的酷事...


RS.Close
设置RS = Nothing


我也是:


Dim cmd作为ADODB.command

设置cmd = Nothing


Dim prm As ADODB.Parameter

设置prm = Nothing


Dim ctl As控制

设置ctl = Nothing


Dim objCbo As Object

设置objCbo = Nothing


我一直认为这些是必要的,但我错过了什么吗?


谢谢,

lq

好了,所以我知道:

Dim RS As ADODB.Recordset
解决方案

设置RS = CurrentProject.Connection.Execute(" EXEC"&" mySPR) OCname")

''让各种各样的酷事发生在这里......

RS.Close
设置RS = Nothing
我也是:

Dim cmd As ADODB.command
设置cmd = Nothing

Dim prm As ADODB.Parameter
设置prm = Nothing

Dim ctl As Control
设置ctl = Nothing

Dim objCbo As Object
设置objCbo = Nothing

我一直都是假设这些是必要的,但我错过了什么吗?

谢谢,
lq




确保你关闭更重要那些记录集,因为它们是一个流行的内存泄漏源b / b
。作为一项规则,我Set x = Nothing对于我设定的任何内容,但需要

,这里有很多争议。最多意味着参考被泄露。 YMMV。


-

''---------------

' 'John Mishefske

''---------------


但是......


Dim str as String

设置str = Nothing


Dim x as Integer

Set x =没什么


???


Lauren Quantrell写道:

但是......

Dim str as String
设置str = Nothing

Dim x as Integer
设置x = Nothing

> ???




No..no ..你不需要使用这些数据类型的Set。对象使用Set命令

来分配内存,然后创建对该内存空间的引用。基本数据类型

不需要这个。相反,你会使用:


Dim str as String

str = Nothing


Dim x as Integer

x = Nothing


但是需要设置对象(如Recordsets或Forms)。查看在线帮助以获取更多信息。


-

''---------------

''John Mishefske

''---------------


OK, so I know to:

Dim RS As ADODB.Recordset
Set RS = CurrentProject.Connection.Execute("EXEC " & "mySPROCname")

''make all sorts of cool stuff happen here...

RS.Close
Set RS = Nothing

and I also:

Dim cmd As ADODB.command
Set cmd = Nothing

Dim prm As ADODB.Parameter
Set prm = Nothing

Dim ctl As Control
Set ctl = Nothing

Dim objCbo As Object
Set objCbo = Nothing

I have always assumed these are necessary, but am I missing anything?

Thanks,
lq

解决方案

Lauren Quantrell wrote:

OK, so I know to:

Dim RS As ADODB.Recordset
Set RS = CurrentProject.Connection.Execute("EXEC " & "mySPROCname")

''make all sorts of cool stuff happen here...

RS.Close
Set RS = Nothing

and I also:

Dim cmd As ADODB.command
Set cmd = Nothing

Dim prm As ADODB.Parameter
Set prm = Nothing

Dim ctl As Control
Set ctl = Nothing

Dim objCbo As Object
Set objCbo = Nothing

I have always assumed these are necessary, but am I missing anything?

Thanks,
lq



Its far more important to ensure you close those Recordsets since they are a popular
source of memory leaks. As a rule I "Set x = Nothing" for anything I set but the need for
that is heavily debated here. At most it means a reference is leaked. YMMV.

--
''---------------
''John Mishefske
''---------------


But...

Dim str as String
Set str = Nothing

Dim x as Integer
Set x = Nothing

???


Lauren Quantrell wrote:

But...

Dim str as String
Set str = Nothing

Dim x as Integer
Set x = Nothing

???



No..no.. You don''t need to use the Set with these data types. Objects use the Set command
to allocate memory and then create a reference to that memory space. The basic data types
do not require this. Instead you''d use:

Dim str as String
str = Nothing

Dim x as Integer
x = Nothing

But objects (like Recordsets or Forms) need to be Set. Check the on-line help for more info.

--
''---------------
''John Mishefske
''---------------


这篇关于什么时候没有比什么都好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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