Delphi XE,Windows 7 64位
当您为一个空应用程序添加语言支持时,会出现内存泄漏(FastMM4)。
如何重现:
- 创建新的VCL表单应用程序
- 修改.dpr并添加
ReportMemoryLeaksOnShutdown := True;
- 构建/运行应用程序并关闭应用程序 ->没有报告泄漏
- 现在添加一种语言(项目 -> 语言 -> 添加)
- 再次构建/运行并关闭应用程序 -> 内存泄漏??
FastMM4完整调试模式报告:
--------------------------------2013/7/16 14:54:34--------------------------------
A memory block has been leaked. The size is: 12
This block was allocated by thread 0x17EC, and the stack trace (return addresses) at the time was:
40455E
40952D
4094C8
409834
409941
450058
74548D76 [Unknown function at FirstHookFunc]
7778FA1A [ZwOpenKey]
75924033 [OpenRegKey]
759240AE [OpenRegKey]
777FA71A [Unknown function at RtlUlonglongByteSwap]
The block is currently used for an object of class: Unknown
The allocation number is: 6
Current memory dump of 256 bytes starting at pointer address 7EF9A610:
6E 00 6C 00 2D 00 42 00 45 00 00 00 41 58 0D 7A 00 00 00 00 C1 A6 F9 7E 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 2E 00 00 00 5E 45 40 00 DD 99 40 00 6D 71 4B 00 98 65 40 00 04 66 40 00
77 A6 40 00 98 7C 4B 00 AA 33 8D 76 F2 9E 7A 77 C5 9E 7A 77 00 00 00 00 EC 17 00 00 EC 17 00 00
1F 9A 40 00 53 7F 42 00 2C 65 40 00 EA 68 40 00 E3 7C 4B 00 AA 33 8D 76 F2 9E 7A 77 C5 9E 7A 77
00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 B6 5C 27 4D 5C 12 4C 00 80 80 80 80
49 A3 D8 B2 80 80 80 80 00 00 00 00 F9 B7 F9 7E 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
65 00 00 00 5E 45 40 00 A7 50 40 00 22 56 40 00 DC 50 40 00 5F 72 4B 00 78 96 44 00 8E 72 4B 00
98 65 40 00 04 66 40 00 77 A6 40 00 98 7C 4B 00 EC 17 00 00 EC 17 00 00 7A 45 40 00 C5 50 40 00
n . l . - . B . E . . . A X . z . . . . Á ¦ ù ~ . . . . . . . .
. . . . . . . . . . . . ^ E @ . Ý ™ @ . m q K . ˜ e @ . . f @ .
w ¦ @ . ˜ | K . ª 3 v ò ž z w Å ž z w . . . . ì . . . ì . . .
. š @ . S B . , e @ . ê h @ . ã | K . ª 3 v ò ž z w Å ž z w
. . . . . . . . . . . . . . . . . . . . ¶ \ ' M \ . L . € € € €
I £ Ø ² € € € € . . . . ù · ù ~ . . . . . . . . . . . . . . . .
e . . . ^ E @ . § P @ . " V @ . Ü P @ . _ r K . x – D . Ž r K .
˜ e @ . . f @ . w ¦ @ . ˜ | K . ì . . . ì . . . z E @ . Å P @ .
--------------------------------2013/7/16 14:54:34--------------------------------
This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):
5 - 12 bytes: Unknown x 1
Note: Memory leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "EnableMemoryLeakReporting".
现在到有趣的部分:删除语言并再次运行->泄漏仍然存在!
我可以通过删除所有与项目相关的文件(.dproj、.dproj2007、.dsk等)来删除泄漏,除了.dpr和.res文件。
有人能解释一下发生了什么吗?
更新
使用详细日志中的地址,似乎我在System.Pas中找到了泄漏。
var
PreferredLanguagesOverride: PChar = nil;
...
procedure SetLocaleOverride(const NewPreferredLanguages: string);
var
L: Integer;
begin
if PreferredLanguagesOverride <> nil then
FreeMem(PreferredLanguagesOverride);
L := Length(NewPreferredLanguages);
if L > 0 then
begin
Inc(L);
GetMem(PreferredLanguagesOverride, L * SizeOf(Char));
MoveChars(NewPreferredLanguages[1], PreferredLanguagesOverride^, L);
end;
end;
调用SetLocaleOverride并为PreferredLanguagesOverride PChar保留内存。我在System.Pas中搜索了FreeMem(PreferredLanguagesOverride),但这是唯一的出现!
更新2
我找到了Delphi调用SetLocaleOverride例程的原因:
当您添加语言支持时,会创建一个注册表键,名称为可执行文件的完整路径,当前系统区域设置作为值: HKEY_CURRENT_USER\Software\Embarcadero\Locales
删除此键可防止Delphi调用SetLocaleOverride例程。
问题:
- 有人可以验证此问题是否存在于较新的Delphi版本中吗?(否则我将进行QC报告)
更新3
已经有 QC报告(105136)并已从XE3修复
问题:有人能向我展示XE3中如何修补此问题吗?