我们需要清除Integer和字符串变量吗?

问题描述 投票:0回答:1

我们需要清除Integerstring变量吗?

我的意思是,我们使用整数变量后,必须将其设置为零,并且还必须清除字符串变量以提高存储性能等?还是什么都没有发生?

编辑:

例如,此代码在服务器中运行24h / 7,请勿关闭或重新启动服务器,并且在5分钟内调用此过程超过3000次。

procedure somejob;
i:integer;
Test1,Test2,Test3,Test4:string;
begin

 {Some more job....}
i := {BIG INTEGER};
Test1:= {BIG STRING};
Test2:= {BIG STRING};
Test3:= {BIG STRING};
Test4:= {BIG STRING};
{some more job....}


{we have to clear these variables or not?}

i:= 0;
Test1:= '';
Test2:='';
Test3:='';
Test4:='';
end;
delphi memory-leaks delphi-7 delphi-xe
1个回答
1
投票

不,在这种情况下,您不必清除任何变量。

字符串是Delphi中的reference counted。这意味着该字符串将在执行例程后自动释放。

整数和其他简单类型在堆栈中分配,当运行线程离开例程时消失。

© www.soinside.com 2019 - 2024. All rights reserved.