Forum > General
Memory Leak. Missing 64 blocks
BlueIcaro:
Hello, I have the following code:
--- Code: ---var
Cadena, NombrePropiedad: string;
J, I: integer;
PP: PPropList;
PPI: Pointer;
PT: PTypeData;
TipoPropiedad: TTypeKind;
b: boolean;
begin
Cadena := '';
PPI := aItem.ClassInfo;
PT := GetTypeData(PPI);
GetMem(PP, PT^.PropCount * SizeOf(PP));
J := GetPropList(aItem.ClassType, PP);
//for I := 0 to J - 1 do
//begin
// with PP^[I]^ do
// begin
// NombrePropiedad := Name;
// end;
// TipoPropiedad := PropType(aItem, NombrePropiedad);
// case TipoPropiedad of
// tkAString:
// begin
// Cadena := GetStrProp(aItem, NombrePropiedad);
// if Cadena <> '' then
// begin
// Cadena := Format('-%s "%s"', [NombrePropiedad, Cadena]);
// aLineas.Add(Cadena);
// end;
// end;
// tkBool:
// begin
// B := GetPropValue(aItem, NombrePropiedad);
// if b then
// begin
// Cadena := Format('-%s ', [NombrePropiedad]);
// aLineas.Add(Cadena);
// end;
// end;
// end;
//end;
Freememory(PP, PT^.PropCount * SizeOf(PP));
--- End code ---
As you can see I comment many code, but I couln't find where is the leak memory.
Any idea
Thanks in advance
/BlueIcaro
Thaddy:
It is FreeMem, NOT FreeMemory.
GetMem:
@Thaddy
Freememory is just an alias for FreeMem.
@BlueIcaro
Your leak originates from Button2Click. Can you post the code? Even better a small demo that shows the issue would be nice.
BlueIcaro:
--- Quote from: GetMem on January 31, 2023, 11:08:34 am ---@Thaddy
Freememory is just an alias for FreeMem.
@BlueIcaro
Your leak originates from Button2Click. Can you post the code? Even better a small demo that shows the issue would be nice.
--- End quote ---
With Freemem I got the same problem because is the same instruccion as you say GetMem
Here is the buttonClick2 Code:
--- Code: ---procedure TForm1.Button2Click(Sender: TObject);
var
E: TCrossConexionList;
Lista, L: TStringList;
I: integer;
begin
if OpenDialog1.Execute then
begin
Lista := TStringList.Create;
Lista.LoadFromFile(OpenDialog1.FileName);
E := TCrossConexionList.Create;
E.LoadFromStrings(Lista);
Memo1.Lines.Clear;
L := E[0].GenerateLines;
FreeAndNil(L);
FreeAndNil(Lista);
FreeAndNil(E);
end;
end;
--- End code ---
Also a attach all project.
/BlueIcaro
howardpc:
Try code such as this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.ShowItemInfo(aItem: TComponent; aLineas: TMemo);var Cadena, NombrePropiedad: String; propCount, i: Integer; PropListPtr: PPropList; TipoPropiedad: TTypeKind; begin Cadena := ''; propCount := GetPropList(aItem.ClassType, PropListPtr); if propCount > 0 then try for i := 0 to propCount - 1 do begin NombrePropiedad := PropListPtr^[I]^.Name; TipoPropiedad := PropType(aItem, NombrePropiedad); case TipoPropiedad of tkAString: begin Cadena := GetStrProp(aItem, NombrePropiedad); if Cadena <> '' then aLineas.Lines.Add('-%s "%s"', [NombrePropiedad, Cadena]); end; tkBool: if {%H-}GetPropValue(aItem, NombrePropiedad) then aLineas.Lines.Add('-%s ', [NombrePropiedad]); end; end; finally Freemem(PropListPtr); end;end;You don't need an explicit GetMem, since the call to GetPropList allocates the memory required.
Navigation
[0] Message Index
[#] Next page