惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
F
Fortinet All Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
量子位
博客园 - 三生石上(FineUI控件)
I
InfoQ
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
D
Docker
美团技术团队
雷峰网
雷峰网
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理

博客园 - USEGEAR

学习unigui【48】lucksheet表格的显示object 学习使用 处理Python对象和列表【5】 学习使用:创建 Python 可调用的 Delphi 函数【4】 学习使用TPythonDelphiVar组件 数据交换Delphi与Python传值【3】 学习使用 数据交换 Delphi 与 Python 传值【2】 学习使用 Python4Delphi 是什么【1】 学习unigui【47】扫码安装apk 学习unigui【46】让客户端浏览器可以选下载你的apk 学习unigui【45】UnimDatePicker等按钮汉化崩溃 学习unigui【44】如何和uinHTMLFrame打交道 学习unigui【43】如何和控件打交道 学习unigui【42】UnimDatePicker的使用 学习unigui【41】htmlframe的交互现象 学习unigui【40】加入监控墙-1 学习unigui【39】单独文件在ms win server 上执行的坑 学习unigui【38】重新认识UUNIGUI--为什么这样快? 站在“架构与性能”层面重新审视 学习unigui【37】nginx的反向代理 ,程序中的重新定向 学习unigui【36】把数据导航放在Unidbgrid脚中 学习unigui【35】dbgrid字段宽度自适应 KingSADA的工业历史数据库的访问
头大的内存泄漏
USEGEAR · 2025-11-27 · via 博客园 - USEGEAR
function LoadTemplateJsonFromDB(ATemplateID: Integer): TJSONObject;//注意返回对象
var
  Q: TFDQuery;
  S: string;
  RootVal: TJSONValue;
  RootArr: TJSONArray;
begin
  Result := nil;

  Q := TFDQuery.Create(nil);
  try
    Q.Connection := UniMainModule.FDConnection1;
    Q.SQL.Text :=
      'SELECT template_json FROM user001.ops_report_template WHERE id = :tid';
    Q.ParamByName('tid').AsInteger := ATemplateID;
    Q.Open;

    if Q.IsEmpty then
      Exit;

    S := Trim(Q.FieldByName('template_json').AsString);
  finally
    Q.Free;
  end;

  if S = '' then
    Exit;
//一定要这样处理!!!!!!
  RootVal := TJSONObject.ParseJSONValue(S);
  if RootVal = nil then
    Exit;

  try
    if RootVal is TJSONArray then
    begin
      RootArr := TJSONArray(RootVal);
      if RootArr.Count > 0 then
        Result := TJSONObject(RootArr.Items[0].Clone);  // ★ Clone 出来交给外部
    end
    else if RootVal is TJSONObject then
      Result := TJSONObject(RootVal.Clone);
  finally
    RootVal.Free;   // ★ 无论如何释放根节点,避免泄漏 TJSONArray/TList
  end;
end;

这个内存泄漏相当难查。是一个非常隐蔽的大坑。