Ich kann das nicht nachvollziehen. Hast du ein funktionsfähiges Testprogramm?
Ich bekomme hier keine Speicherlecks:
Delphi-Quellcode:
// JCL_DEBUG_EXPERT_GENERATEJDBG OFF
// JCL_DEBUG_EXPERT_INSERTJDBG OFF
program AtrtibTestProject;
{$APPTYPE CONSOLE}
{$R *.res}
uses
FastMM4,
System.SysUtils,
System.Rtti;
type
MyAttribute =
class(TCustomAttribute);
TMyObject =
class(TObject)
public
[MyAttribute]
procedure test();
virtual;
end;
procedure p();
var
interceptor: TVirtualMethodInterceptor;
myObject: TMyObject;
begin
interceptor :=
nil; myObject :=
nil;
try
myObject := TMyObject.Create();
interceptor := TVirtualMethodInterceptor.Create( myObject.ClassType() );
interceptor.OnBefore :=
procedure(
instance: TObject;
method: TRttiMethod;
const args: TArray<TValue>;
out doInvoke: Boolean;
out result: TValue
)
var
attributes: TArray<TCustomAttribute>;
begin
attributes := method.GetAttributes();
WriteLn('
We found ', Length(attributes), '
attributes');
end;
interceptor.Proxify(myObject);
myObject.test();
finally
if Assigned(interceptor)
then
begin
interceptor.Unproxify(myObject);
interceptor.Destroy();
end;
myObject.Free();
end;
end;
{ TMyObject }
procedure TMyObject.test();
begin
WriteLn('
Hello World');
end;
begin
ReportMemoryLeaksOnShutdown := True;
try
p();
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
readln;
end.