拆分后用擦除清理? [英] Cleanup with Erase after Split?

查看:75
本文介绍了拆分后用擦除清理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要写一个像下面这样的函数,我很多时候会打电话给

。所以我关心可能的内存泄漏。

我认为是否应该使用Erase取决于Split

是否创建动态数组(类似于ReDim a(2)) 。我有一种直觉感觉

它确实如此。意见?


Dim a()as String

a =拆分(" part1 | part2 | part3"," |")

''使用的代码就在这里

擦除


-Tom。

解决方案

正如你无疑已经知道的那样,'a''一旦超出范围就会被解除分配。因此,如果它是一个过程级变量,它将在退出程序时被释放

。显式擦除IMO的唯一好处是

,如果数组大于<,并且你已经完成它,但它不会

出去范围一段时间 (不管它是什么意思)。然后,擦除可以

立即用于回收空间。


HTH,

TC


" Tom van Stiphout" <到***** @ no.spam.cox.net>在留言中写道

news:f8 ******************************** @ 4ax.com ...

我打算写一个像下面这样的函数,我很多时候会打电话给很多次。所以我关心可能的内存泄漏。
我认为是否应该使用Erase取决于Split是否创建动态数组(类似于ReDim a(2))。我有直觉感觉它确实如此。意见?

Dim a()as String
a = Split(" part1 | part2 | part3"," |")
''代码使用了一个去在这里
擦除

-Tom。



2003年12月12日星期五16:03:48 +1200 ,TC < a@b.c.d>写道:


嗯,你可能是对的,但我认为记忆方面存在差异

介于a之间。和记忆a分配。该变量将超出

范围,因为堆栈帧将被清除,但如果a是动态的
数组,则其动态分配的内存不会。我的阵列将是

小,可能是4或5个元素,但我会称这个函数很多

次。


- 汤姆。

正如你无疑已经知道的那样,'a''一旦超出范围就会被解除分配。因此,如果它是一个过程级变量,它将在退出程序时解除分配。显式擦除IMO的唯一好处是,如果阵列大于<,并且你已经完成了它,但它将不会超出范围一段时间。 (不管它是什么意思)。然后,擦除可以用来立即回收空间。

HTH,
TC

Tom van Stiphout <到***** @ no.spam.cox.net>在消息中写道
新闻:f8 ******************************** @ 4ax.com .. < blockquote class =post_quotes>我要写一个像下面这样的函数,我很多时候会打电话给很多次。所以我关心可能的内存泄漏。
我认为是否应该使用Erase取决于Split是否创建动态数组(类似于ReDim a(2))。我有直觉感觉它确实如此。意见?

Dim a()as String
a = Split(" part1 | part2 | part3"," |")
''代码使用了一个去在这里
擦除

-Tom。




但是什么引导你说变量可以超出范围>没有<

相关内存被解除分配?


TC

" Tom van Stiphout <到***** @ no.spam.cox.net>在消息中写道

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

On Fri,2003年12月12日16:03:48 +1200,TC < a@b.c.d>写道:

嗯,你可能是对的,但我认为在记忆方面a之间存在差异。和记忆a分配。由于堆栈帧将被清除,变量将超出范围,但如果a是动态数组,则其动态分配的内存不会。我的阵列很小,可能是4或5个元素,但我会多次调用这个函数。

-Tom。

你无疑已经知道了,''a''一旦超出范围就会被解除分配。因此,如果它是一个过程级变量,则退出该过程将是
deallocated。显式擦除,IMO,
的唯一好处是,如果数组大于<,并且你已经完成了它,但是它会在一段时间内超出范围b $ b (不管它是什么意思)。然后,擦除
可以用来立即收回空间。

HTH,
TC

Tom van Stiphout <到***** @ no.spam.cox.net>在消息中写道
新闻:f8 ******************************** @ 4ax.com .. < blockquote class =post_quotes>我要写一个像下面这样的函数,我很多时候会打电话给很多次。所以我关心可能的内存泄漏。
我认为是否应该使用Erase取决于Split是否创建动态数组(类似于ReDim a(2))。我有直觉感觉它确实如此。意见?

Dim a()as String
a = Split(" part1 | part2 | part3"," |")
''代码使用了一个去在这里
擦除

-Tom。



I''m about to write a function like below, which I''m going to call a
lot of times. So I care about possible memory leaks.
I think whether I should use Erase or not depends on whether Split
creates a dynamic array (similar to ReDim a(2)). I have a gut feeling
it does. Opinions?

Dim a() as String
a = Split("part1|part2|part3", "|")
'' code that uses a goes here
Erase a

-Tom.

解决方案

As you doubtless already know, ''a'' will be deallocated as soon as it goes
out of scope. So if it is a procedure level variable, it will be deallocated
on exit from the procedure. The only benefit to an explicit erase, IMO, is
if the array is >way large<, and you have finished with it, but it will not
go out of scope "for some time" (whatever that means). Then, the erase could
be used to reclaim the space immediately.

HTH,
TC

"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:f8********************************@4ax.com...

I''m about to write a function like below, which I''m going to call a
lot of times. So I care about possible memory leaks.
I think whether I should use Erase or not depends on whether Split
creates a dynamic array (similar to ReDim a(2)). I have a gut feeling
it does. Opinions?

Dim a() as String
a = Split("part1|part2|part3", "|")
'' code that uses a goes here
Erase a

-Tom.



On Fri, 12 Dec 2003 16:03:48 +1200, "TC" <a@b.c.d> wrote:

hmmm, you may be right, but I think memory-wise there is a difference
between "a" and the memory "a" allocates. The variable will go out of
scope as the stack frame will be cleaned up, but if a is a dynamic
array, its dynamically allocated memory will not. My arrays will be
small, perhaps 4 or 5 elements, but I will call this function many
times.

-Tom.

As you doubtless already know, ''a'' will be deallocated as soon as it goes
out of scope. So if it is a procedure level variable, it will be deallocated
on exit from the procedure. The only benefit to an explicit erase, IMO, is
if the array is >way large<, and you have finished with it, but it will not
go out of scope "for some time" (whatever that means). Then, the erase could
be used to reclaim the space immediately.

HTH,
TC

"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:f8********************************@4ax.com.. .

I''m about to write a function like below, which I''m going to call a
lot of times. So I care about possible memory leaks.
I think whether I should use Erase or not depends on whether Split
creates a dynamic array (similar to ReDim a(2)). I have a gut feeling
it does. Opinions?

Dim a() as String
a = Split("part1|part2|part3", "|")
'' code that uses a goes here
Erase a

-Tom.




But what leads you to say that the variable can go out of scope >without<
the associated memory being deallocated?

TC
"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:l3********************************@4ax.com...

On Fri, 12 Dec 2003 16:03:48 +1200, "TC" <a@b.c.d> wrote:

hmmm, you may be right, but I think memory-wise there is a difference
between "a" and the memory "a" allocates. The variable will go out of
scope as the stack frame will be cleaned up, but if a is a dynamic
array, its dynamically allocated memory will not. My arrays will be
small, perhaps 4 or 5 elements, but I will call this function many
times.

-Tom.

As you doubtless already know, ''a'' will be deallocated as soon as it goes
out of scope. So if it is a procedure level variable, it will be deallocatedon exit from the procedure. The only benefit to an explicit erase, IMO, isif the array is >way large<, and you have finished with it, but it will notgo out of scope "for some time" (whatever that means). Then, the erase couldbe used to reclaim the space immediately.

HTH,
TC

"Tom van Stiphout" <to*****@no.spam.cox.net> wrote in message
news:f8********************************@4ax.com.. .

I''m about to write a function like below, which I''m going to call a
lot of times. So I care about possible memory leaks.
I think whether I should use Erase or not depends on whether Split
creates a dynamic array (similar to ReDim a(2)). I have a gut feeling
it does. Opinions?

Dim a() as String
a = Split("part1|part2|part3", "|")
'' code that uses a goes here
Erase a

-Tom.



这篇关于拆分后用擦除清理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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