Search the Community
Showing results for tags 'memoryleak'.
Found 4 results
-
This is a simplified version of what I had in my app. procedure Test(); var TerminateProc: TThreadProcedure; S: string; begin S := 'Terminated'; TerminateProc := procedure begin ShowMessage(S); end; TThread.CreateAnonymousThread( procedure begin // Do stuff TThread.Queue(nil, TerminateProc); TerminateProc := nil; // Memory leak without this end).Start; end; I had to insert the statement with the comment "Memory leak without this" to avoid memory leaks. Any idea why the compiler does not free TerminateProc on its own? Is this a compiler bug?
- 4 replies
-
- anonymousmethods
- threads
-
(and 1 more)
Tagged with:
-
Memory leak on TBlobField(FieldByname(field_name)).SavetoStream(Stream);
alogrep posted a topic in VCL
Hi. Madexcept shows a leak on this part of my code: TBlobField(FieldByname('image')).SavetoStream(Stream); var Stream: TMemoryStream; .... Stream:=TMemoryStream.create; TBlobField(FieldByname('image')).SavetoStream(Stream); if Stream.Size > 0 then begin FindGraphicClass(Stream.Memory^, Stream.Size, GraphicClass); ..... ///// end; Stream.free; end; Anybody knows that is wrong with my code? -
Hi all. What I love of Delphi is memory management and overall the integration of FastMM and related memory leak management. All my projects are Memory Leak Free (just thanks to reports of FastMM which permits me to create a better code). Now I'm migrating some programs to Python using DelphiVCL and I'm falling into odd memory leaks. In a Python (3.9.12) application that uses DelphiVCL (0.1.40) I've noticed a continuous memory leak in some simple operations with VCL objects like Checkbox. I've attached a very simple Python program that uses a Timer to constantly update the Enabled state of a Checkbox. In the sample, I've also added a const to enable a tracemalloc and confirm the continue grow of memory used by <Checkbox>.Enabled = True # enable/disable tracemalloc to exclude the memory impact of tracemalloc TRACEMALLOC_ENABLED = False By default, TRACEMALLOC_ENABLED is set to False to remove any impact of tracemalloc framework. If enabled, the first mouse down on the form capture the BASE snapshot of memory. Any following mouse down, report on console the comparison of current snapshot with the first. Initially, tracemalloc internals is in the top ten results, but after some time Checkbox1.Enabled = True gain the top. If I disable the interesting lines, commenting on them, any memory leak disappears: def __on_timer(self, sender): """ self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True self.CheckBox1.Enabled = True """ I've placed many CheckBox1.Enabled to exasperate the case-test but usually, I do this for a lot of controls in update events. This is the memory usage captured with Process Explorer on running Python process with TRACEMALLOC_ENABLED = False: test.zip
-
Help with dynamic record memory leak
Gary posted a topic in Algorithms, Data Structures and Class Design
Delphi 10.4.1 Windows 10 Why does this leak memory? FastMM4 reports A memory block has been leaked. The size is: 36 This block was allocated by thread 0x948, and the stack trace (return addresses) at the time was: 4070A2 [System.pas][System][@GetMem$qqri][4843] 40A0F7 [System.pas][System][@NewUnicodeString$qqri][25659] 40A584 [System.pas][System][@UStrAsg$qqrr20System.UnicodeStringx20System.UnicodeString][26643] 615C6A [Unit1.pas][Unit1][TForm1.GetReminder][65] 616166 [Unit1][Generics.Collections.%TList__1$19Unit1.TReminderItem%.Create] 615A34 [Unit1.pas][Unit1][TForm1.Button1Click][46] 770168CF [GetWindowLongW] 720A55DC [Unknown function at SetWindowSubclass] 4086D3 [System.pas][System][@IsClass$qqrxp14System.TObjectp17System.TMetaClass][18453] 553531 [Vcl.Controls.pas][Vcl.Controls][Controls.TControl.Click][7596] 56C28B [Vcl.StdCtrls.pas][Vcl.StdCtrls][Stdctrls.TCustomButton.Click][5609] type TReminderItem = record public RecordID: Integer; EmployeeID: Integer; EmployeeName: String; HireDate: TDate; LastDate: TDate; Notes: String; procedure Clear; end; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private procedure GetReminder(AList: TList<TReminderItem>); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var LList : TList<TReminderItem>; LReminderItem : TReminderItem; PReminderItem : ^TReminderItem; begin LList := TList<TReminderItem>.Create; try GetReminder(LList); ShowMessage(LList[0].EmployeeName); finally for LReminderItem in LList do LReminderItem.Clear; LList.Free; end; end; procedure TForm1.GetReminder(AList :TList<TReminderItem>); var LReminderItem: ^TReminderItem; begin New(LReminderItem); LReminderItem.RecordID := 1; LReminderItem.EmployeeID := 1; LReminderItem.EmployeeName := 'Test'; LReminderItem.HireDate := Now; LReminderItem.LastDate := Now;; LReminderItem.Notes := 'A Note'; AList.Add(LReminderItem^); end; { TReminderItem } procedure TReminderItem.Clear; begin Self := Default(TReminderItem); end; This is just my latest attempt, I have tried Finalize, FinalizeRecord, FreeMem. The Clear procedure is also an attempt after seeing it in a different post. What is the proper way to free memory of a record I create in a list? Thanks in advance, Gary Unit1.pas Unit1.dfm