regex - 必须释放创建的 System.RegularExpressions 对象的内存吗?

标签 regex delphi

我在 Delphi Rio 10.3.3 中使用 System.RegularExpressions 编写了此代码:

var
  S: string;
  Itf: string; // Interface section
  TempList: TStringList;
  ThisRegexObj: System.RegularExpressions.TRegEx;
  ThisMatchResult: System.RegularExpressions.TMatch;
begin
  ThisRegexObj := System.RegularExpressions.TRegEx.Create(
    '((?<=procedure ).*(?=\())|(?<=procedure ).*(?!\()', [roIgnoreCase]);
  ThisMatchResult := ThisRegexObj.Match(Itf);
  TempList := TStringList.Create;
  try
    while ThisMatchResult.Success do
    begin
      TempList.Add(ThisMatchResult.Value);
      ThisMatchResult := ThisMatchResult.NextMatch;
    end;
    mmoTokens.Lines.Add('Interface Procedure names: ' + TempList.CommaText);
  finally
    TempList.Free;
  end;

之后必须释放对象ThisRegexObjThisMatchResult的内存吗?

最佳答案

Must memory of created System.RegularExpressions objects be released?

对象的实例,并且它们总是需要被释放。

但是,TRegExTMatch 根本不是类,而是记录类型。因此,您的 ThisRegexObjThisMatchResult 不是对象,而是记录。并且记录由编译器自动处理。

因此,您不需要释放任何内容(实际上,您不能这样做 - 这些记录中没有免费成员)。

关于regex - 必须释放创建的 System.RegularExpressions 对象的内存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59234114/

相关文章:

javascript - 使用 JavaScript 更改字符串

c++ - 如何在 C++11 中使用 <regex>

multithreading - TThreadList和 “with”语句

delphi - FireDac 查询字段大小不会因 SQL 更改而更新

winforms - 如何在 WinForms 应用程序中使用 Delphi (2007) 控件?

javascript - 正则表达式请求 - 删除字符

python - 从列表中获取子字符串

java - 正则表达式仅允许两种模式中的一种

delphi - 我的 Delphi 应用程序完成初始化后,我应该在哪里放置要执行的代码?

delphi - 在delphi中使用数据模块分离数据集实例