简体   繁体   English

FastMM:如何为所有 unicode 或 ansi 字符串 RegisterExpectedMemoryLeak?

[英]FastMM: how can I RegisterExpectedMemoryLeak for all unicode or ansi strings?

There are three functions to register an expected memory leak in fastmm:在 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;

but they are no applicable for string types.但它们不适用于字符串类型。 Any idea ?任何的想法 ?

You can register these leaks as generic leaks, using function FastMM_RegisterExpectedMemoryLeak(ALeakedBlockSize: NativeInt; ACount: Integer = 1): Boolean; overload;您可以将这些泄漏注册为通用泄漏,使用function FastMM_RegisterExpectedMemoryLeak(ALeakedBlockSize: NativeInt; ACount: Integer = 1): Boolean; overload; function FastMM_RegisterExpectedMemoryLeak(ALeakedBlockSize: NativeInt; ACount: Integer = 1): Boolean; overload;

Here is an example:下面是一个例子:

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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM