我正在使用GNUGetText来翻译我的应用。 刚刚安装了Eurekalog来检查内存泄漏并确保应用程序运行清晰。 每次我关闭应用程序时,都会遇到大量可能的内存泄漏,其中一个是:
|+Leak #3: Type=BSTR (Memory): $058A0A24 - SysReAllocStringLen; Count=1 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|00000002|04 |00000000|00825A8F|myapp.exe|00425A8F|LcUnit |TGnuGettextInstance |dgettext |1564[7] |
|00000002|04 |00000000|00823BBD|myapp.exe|00423BBD|LcUnit | |dgettext |737[1] |
|00000002|04 |00000000|008239FF|myapp.exe|004239FF|LcUnit | |ResourceStringGettext |658[10] |
|00000002|04 |00000000|00827E65|myapp.exe|00427E65|LcUnit |TGnuGettextInstance |LoadResString |2484[45] |
|00000002|04 |00000000|00824407|myapp.exe|00424407|LcUnit | |LoadResStringW |1054[1] |
|00000002|03 |00000000|00A01931|myapp.exe|00601931|cxClasses | |cxGetResourceString | |
|00000002|03 |00000000|00B45E17|myapp.exe|00745E17|cxGridCustomView |TcxCustomGridCellViewInfo |CalculateParams | |
|00000002|03 |00000000|00B4673D|myapp.exe|0074673D|cxGridCustomView |TcxCustomGridCellViewInfo |Calculate | |
|00000002|03 |00000000|00BD1471|myapp.exe|007D1471|cxGridCustomTableView |TcxCustomGridPartViewInfo |CalculateInvisible | |
|00000002|03 |00000000|00B47C30|myapp.exe|00747C30|cxGridCustomView |TcxCustomGridViewInfo |MainCalculate | |
|00000002|03 |00000000|00B2C438|myapp.exe|0072C438|cxGridDetailsSite |TcxCustomGridDetailsSiteViewInfo|Calculate | |
|00000002|03 |00000000|00B313D6|myapp.exe|007313D6|cxGrid |TcxGridLayoutChange |Execute | |
|00000002|03 |00000000|00B33EA9|myapp.exe|00733EA9|cxGrid | |DoFinalChanges | |
|00000002|03 |00000000|00B33F3A|myapp.exe|00733F3A|cxGrid |TcxCustomGrid |DoUpdate | |
|00000002|03 |00000000|00B34286|myapp.exe|00734286|cxGrid |TcxCustomGrid |EndUpdate | |
|00000002|03 |00000000|00B33E9C|myapp.exe|00733E9C|cxGrid | |DoFinalChanges | |
|00000002|03 |00000000|00B33F3A|myapp.exe|00733F3A|cxGrid |TcxCustomGrid |DoUpdate | |
|00000002|03 |00000000|00B34286|myapp.exe|00734286|cxGrid |TcxCustomGrid |EndUpdate | |
|00000002|03 |00000000|00B49C55|myapp.exe|00749C55|cxGridCustomView |TcxCustomGridView |GridEndUpdate | |
|00000002|03 |00000000|00C45821|myapp.exe|00845821|cxGridDBDataDefinitions|TcxGridDBDataController |EndFullUpdate | |
|00000002|03 |00000000|0079FDDD|myapp.exe|0039FDDD|Data.DB |TDataLink |DataEvent | |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
指向以下功能:
function TGnuGettextInstance.dgettext(const szDomain: DomainString;
const szMsgId: MsgIdString): TranslatedUnicodeString;
begin
if not Enabled then begin
{$ifdef DXGETTEXTDEBUG}
DebugWriteln ('Translation has been disabled. Text is not being translated: '+szMsgid);
{$endif}
Result:=szMsgId;
end else begin
Result:=UTF8Decode(EnsureLineBreakInTranslatedString(getdomain(szDomain,DefaultDomainDirectory,CurLang).gettext(StripCRRawMsgId(utf8encode(szMsgId)))));
{$ifdef DXGETTEXTDEBUG}
if (szMsgId<>'') and (Result='') then
DebugWriteln (Format('Error: Translation of %s was an empty string. This may never occur.',[szMsgId]));
{$endif}
end;
end;
特别是在以下一行:
Result:=UTF8Decode(EnsureLineBreakInTranslatedString(getdomain(szDomain,DefaultDomainDirectory,CurLang).gettext(StripCRRawMsgId(utf8encode(szMsgId)))));
有什么想法吗? 帮助赞赏。
答案 0 :(得分:2)
许多像这样出现的内存泄漏是次要的;你没有找到答案,试图直接从这个列表中追踪它们。查找添加了对象或复制字符串的TStringList条目。也是您为.Data属性分配内容的位置。您似乎正在向cxGrid提供一些未正确管理的内容。如果所有这些都来自两个参考文献,我不会感到惊讶!通过添加一个obj.Free调用finally子句,我已经看到了几十个泄漏报告消失了。