Forum > GTK

[solved] Unreleased DCs and unreleased GDIObjects - TImage memory leaks

(1/4) > >>

andyH:
Got an application which is closed with application.Terminate. When it closes I get the following error messages in the console:

--- Code: Diff  [+][-]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";}};} ---[TGtk2WidgetSet.Destroy] WARNING: There are 3 unreleased DCs, a detailed dump follows:[TGtk2WidgetSet.Destroy]  DCs:   00007FFFEE1C0E40 00007FFFEE1C0C40 00007FFFEE1C0A40[TGtk2WidgetSet.Destroy] WARNING: There are 6 unreleased GDIObjects, a detailed dump follows:[TGtk2WidgetSet.Destroy]   GDIOs: 00007FFFF7F6E2C0 00007FFFF7F6E240 00007FFFF7F6D7C0 00007FFFF7F6E140 00007FFFF7F6D6C0 00007FFFF7F6D740[TGtk2WidgetSet.Destroy]   gdiBitmap: 6I thought the first three might be because I have some images/logos in the app and hadn't TImage.Free on completion, but this made no difference. As far as I'm aware all my Tobjects have .free when I've finished with them.

What are they and what am I doing wrong or not doing? A search on the web did not throw up anything useful.

Running Linux Mint 19.0 cinnamon and lazarus 2.0.2.

Soner:
Did you create some objects manually and how? Like this:
MyObject:=TMyObject.Create(nil);
or like this:
MyObject:=TMyObject.Create(self);
(TMyObject can be TButton, TImage or something else)

When you created objects with nil as owner then they will be never freed. Because they don't exist in any list.
In LCL every object deletes it's child on deletion, application its forms and form its childs like button, panel...

howardpc:

--- Quote from: andyH on June 09, 2019, 11:35:31 am ---Got an application which is closed with application.Terminate. When it closes I get the following error messages
--- End quote ---
Without the code that produces the errors it is not possible to say how these errors arise, since they come not from Lazarus but from the gtk libraries, which don't usually have debugging information you can use to trace the call chain that raised such errors.
It could be to do with the parenting of your controls rather than their freeing, since it seems to be related to freeing of system resources you use, not access violation caused by incorrect destruction.

andyH:
Yes, with the exception of the mainform, all forms and objects are created manually and some are MyObject:=TMyObject.Create(nil), an example being:


--- 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";}};} ---SaveDialog:= TSaveDialog.Create(nil);  
I did try SaveDialog:= TSaveDialog.Create(self) but I was getting compile errors - identifier not found "self". And when I'm finished with SaveDialog I have a SaveDialog.Free. From what you're saying this doesn't work, but I will check through my code to make sure every object has a corresponding .Free when finished.

Thanks for the pointer, I don't really understand .create(TheOwner : TComponent) and so far have been using self or nil where self doesn't work. Nor have I found anything useful on the web to improve my understanding.

Soner:
When I can't use self in TSomething.Create(self) then I use the variable application or a object variable in same scope or some global object.
Or you can also use try..finally-blocks and free the objects self:


--- 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";}};} --- SaveDialog:= TSaveDialog.Create(nil); try //here you can access Savedialogfinally SaveDialog.Free;end; 
Sometimes I set objects at application start to nil and checks at end to nil:

--- 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.FormCreate(Sender: TObject);begin  FormAbout:=nil;end; procedure TForm1.FormDestroy(Sender: TObject);begin  if Assigned(FormAbout) then FormAbout.Free;end; 

Navigation

[0] Message Index

[#] Next page

Go to full version