Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi FastMM:如何为所有unicode或ansi字符串注册ExpectedMemoryLeak?_Delphi_Fastmm - Fatal编程技术网

Delphi FastMM:如何为所有unicode或ansi字符串注册ExpectedMemoryLeak?

Delphi FastMM:如何为所有unicode或ansi字符串注册ExpectedMemoryLeak?,delphi,fastmm,Delphi,Fastmm,有三种功能可在fastmm中注册预期内存泄漏: function FastMM_RegisterExpectedMemoryLeak(ALeakedPointer: Pointer): Boolean; overload; function FastMM_RegisterExpectedMemoryLeak(ALeakedObjectClass: TClass; ACount: Integer = 1): Boolean; overload; function FastMM_RegisterEx

有三种功能可在fastmm中注册预期内存泄漏:

function FastMM_RegisterExpectedMemoryLeak(ALeakedPointer: Pointer): Boolean; overload;
function FastMM_RegisterExpectedMemoryLeak(ALeakedObjectClass: TClass; ACount: Integer = 1): Boolean; overload;
function FastMM_RegisterExpectedMemoryLeak(ALeakedBlockSize: NativeInt; ACount: Integer = 1): Boolean; overload;
但它们不适用于字符串类型。
有什么想法吗?

您可以使用
函数FastMM\u registereExpectedMemoryLeak(ALeakedBlockSize:NativeInt;ACount:Integer=1):布尔;超载

以下是一个例子:

program StringLeakDemo;

{$APPTYPE CONSOLE}

uses
  FastMM5,
  System.SysUtils;

const Leakee = 'string which leaks';
var Z: ^String;

begin
  FastMM_MessageBoxEvents := [Low(TFastMM_MemoryManagerEventType) .. High(TFastMM_MemoryManagerEventType)];
  FastMM_RegisterExpectedMemoryLeak(32 + Length(Leakee), 1);

  GetMem(Z, SizeOf(string));
  Z^ := Leakee;
  FreeMem(Z);
end.

字符串被引用计数。它们会自动释放。您能举一个您试图检测的案例的例子吗?不泄漏字符串不是更容易吗?通常泄漏的是具有字符串属性的对象。修复对象泄漏,字符串泄漏也会消失。#David:这就是我想要实现的#Brian:问题是,没有对象泄漏,只有来自任何地方的真正unicode泄漏OK,但这只是一个已知固定大小字符串的解决方案。但是我正在寻找排除所有大小的unicode字符串泄漏的可能性…这似乎破坏了泄漏检查的整个想法,但是如果您仍然希望这样做,那么除了修改FastMM5.pas使其不会报告字符串泄漏之外,似乎没有其他方法。