tags:

views:

223

answers:

2
FUNCTION SystemspartsClT.KeyFound(Key : AluCostDict.SystemspartskeyT) : BOOLEAN;
VAR v :  Variant;
BEGIN
   v      := VarArrayCreate([0,1], VarInteger);
   v[0]   := Key.System;
   v[1]   := Key.PartType;
   Sucess := t.Locate('System;PartType', v, []);
   v      := NULL;
   Result := Sucess;
END;

I am using Delphi for Win32.

Does this function create a memory leak or not ?

Should I free the variant v as vararray and how?

Should I free or initialize the local variant v?

+6  A: 

It's not a leak, but it's way too much code for a fairly simple task. Try:

FUNCTION SystemspartsClT.KeyFound(
    Key : AluCostDict.SystemspartskeyT) : BOOLEAN;
BEGIN
   Result := t.Locate('System;PartType', 
                 VarArrayOf([Key.System, Key.PartType]), []);
END;
Craig Stuntz
+4  A: 

No, no and no. Variants and variant arrays are managed by the compiler. They get initialized when you create them and freed when they go out of scope. The only way they could create a memory leak is if you assigned an object to the variant's value then forgot to free it.

Mason Wheeler