清理对象变量 - 请MVP [英] Cleaning up object variables - MVPs please

查看:66
本文介绍了清理对象变量 - 请MVP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个

主题上看过多个帖子(过去6个月左右有几个),但我想澄清一下我的做法。我理解需要通过将它们设置为Nothing和/或关闭

来清理对象变量,但我不确定订单。


据我所知,我创建的所有对象变量都是:


设置rs = SomeExistingRecordset


需要通过以下方式清理:


rs.Close

设置rs =无


那些我没有创建如:


设置db = CurrentDB




设置db = DBEngine(0 )(0)


只需要通过以下方式清理:


设置db = Nothing


1)Close方法和Set语句的顺序是否重要?


2)这些实践是否充分释放了对象使用的内存

变量?


3)对象变量如Recordsets,

连接以及其他类型的指针是否不需要关闭?


4)如何指针是否需要处理容器?


提前感谢您重新访问一个非常古老的主题。

解决方案

< blockquote>你可以很好地清理MVP代码,删除每三行作为

冗余和每三行(剩下的)作为

的表现根深蒂固迷信。取其余部分并删除每三行

,这是古老的。剩下的往往是非常好的东西,根本不像你的主题那样令人反感。


莱尔费尔菲尔德 < ly *********** @ aim.comwrote in message

news:11 ******************* ***@i3g2000cwc.googlegro ups.com ...


剩下的东西往往是非常好的东西,不是没有

作为你的主题行是令人反感的。



我以为只是我才会冒犯他人。显然不是。


基思。




Keith Wilby写道:


" Lyle Fairfield" < ly *********** @ aim.comwrote in message

news:11 ******************* ***@i3g2000cwc.googlegro ups.com ...


剩下的东西往往是非常好的东西,不是没有

作为主题行是令人反感的。



我以为只是我才会冒犯他人。显然不是。


基思。



我想如果我更聪明,我可能会冒犯某人暗示

这样一个简单的问题只能由MVP回答。这是那些类似MLH的帖子中的一个

,这可以很容易地通过查看这里的b $ b来回答。或者MVP指定是拥有大脑的先决条件?我认为很多MVP甚至在指定之前都是非常尖锐的......显示我所知道的......


I''ve seen multiple threads (several in the last 6 months or so) on this
topic, but I wanted to clarify my practices. I understand the need for
cleaning object variables by setting them to Nothing and/or closing
them, but I''m not sure about the order.

As I understand it all object variables that I create like:

Set rs = SomeExistingRecordset

need to be cleaned up via:

rs.Close
Set rs = nothing

Those I didn''t create like:

Set db = CurrentDB

or

Set db = DBEngine(0)(0)

need to be cleaned only via:

Set db = Nothing

1) Is the order of the Close method and the Set statement important?

2) Are these practices adequately freeing the memory used by the object
variables?

3) Is the Close unnecessary for object variables like Recordsets,
Connections, and other pointers of the sort?

4) How should pointers to Containers be handled?

Thanks in advance for revisiting a very old topic.

解决方案

You can pretty well clean up MVP code by removing every third line as
redundant and every third line (of what''s left) as a manifestation of
entrenched superstition. Take the remainder and remove every third line
of that as archaic. What''s left is often pretty good stuff that isn''t
as objectionable as your subject line at all.


"Lyle Fairfield" <ly***********@aim.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...

What''s left is often pretty good stuff that isn''t
as objectionable as your subject line at all.

I thought it was just me who''d taken offense. Apparently not.

Keith.



Keith Wilby wrote:

"Lyle Fairfield" <ly***********@aim.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...

What''s left is often pretty good stuff that isn''t
as objectionable as your subject line at all.


I thought it was just me who''d taken offense. Apparently not.

Keith.

I guess if I were smarter, I might take offense at someone implying
that such a simple question could only be answered by an MVP. It''s one
of those MLH-like posts, which could easily be answered by looking it
up here. Or is an MVP designation a prerequisite to having brains? I
thought lots of MVPs were pretty sharp even before they were
designated... shows what I know!!!


这篇关于清理对象变量 - 请MVP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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