SetLength申请的内存如何释放?

zhourongbiao 2005-05-14 12:15:23
用什么函数?
...全文
942 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xwhope 2005-05-16
  • 打赏
  • 举报
回复
Delphi syntax:

procedure SetLength(var S; NewLength: Integer);

Description

S is a Delphi string or dynamic-array variable.

NewLength is the new number of characters or elements in S.

For a short-string variable, SetLength simply sets the length-indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255.

For a long-string or dynamic-array variable, SetLength reallocates the string or array referenced by S to the given length. Existing characters in the string or elements in the array are preserved, but the content of newly allocated space is undefined. The one exception is when increasing the length of a dynamic array in which the elements are types that must be initialized (strings, Variants, Variant arrays, or records that contain such types). When S is a dynamic array of types that must be initialized, newly allocated space is set to 0 or nil.

For dynamic arrays, SetLength may take more than one length parameter (up to the number of array dimensions). Each parameter specifies the number of elements along a particular dimension.

Following a call to SetLength, S is guaranteed to reference a unique string or array梩hat is, a string or array with a reference count of one. If there is not enough memory available to reallocate the variable, SetLength raises an EOutOfMemory exception.
xwhope 2005-05-16
  • 打赏
  • 举报
回复
delphi will free memory automatically
ly_liuyang 2005-05-16
  • 打赏
  • 举报
回复
Setlength中,0参数就是

http://lysoft.7u7.net
zhouhaijun2 2005-05-16
  • 打赏
  • 举报
回复
freeandnil()
gwolf 2005-05-14
  • 打赏
  • 举报
回复
不需要显式释放
happy00 2005-05-14
  • 打赏
  • 举报
回复
delphi will free memory automatically
何鲁青 2005-05-14
  • 打赏
  • 举报
回复
不会出现内存泄漏,所以不用担心什么...
何鲁青 2005-05-14
  • 打赏
  • 举报
回复
不用自己释放的
procedure TForm1.Button1Click(Sender: TObject);
var arr:array of Char;
begin
setlength(arr,10);//申请内存
setlength(arr,0);//这里申请的内存被自动释放了
arr:=nil;//释放arr
end;
q_qi2001 2005-05-14
  • 打赏
  • 举报
回复
用Free方法
hjf8086 2005-05-14
  • 打赏
  • 举报
回复
自动释放
delphfan 2005-05-14
  • 打赏
  • 举报
回复
用动态数组,最终把数组释放就好了

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧