Forum > General

[SOLVED] To Free, or not to Free?

(1/1)

Slyde:
Does TForm Free sm when sm's Ok button's clicked?


--- 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";}};} ---var  sm: TForm;begin  sm:= CreateMessageDialog('Well done', mtCustom, [mbOK]);  sm.Position:= poOwnerFormCenter;  sm.ShowModal;end;
Or do I need to do it?


--- 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";}};} ---var  sm: TForm;begin  sm:= CreateMessageDialog('Well done', mtCustom, [mbOK]);  sm.Position:= poOwnerFormCenter;  sm.ShowModal;  sm.Free;end;
Not a hassle one way or the other.  But since the both blocks of code run, I was wondering if the top block's giving a memory leak.

bytebites:
Correct answer is Project options -> Debugging -> Use Heap trace -unit

Slyde:
Thank you.

dseligo:
IMHO, you have to free it.

There is no owner set in creation of form, so it isn't freed automatically:

--- 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";}};} ---inherited CreateNew(nil, 1);

Slyde:
Hey, dseligo.

That's what I've done, just to be on the safe side.  I actually got that code from the forum, here. And it was given without Freeing the dialog box, which no one said anything to the contrary.  But it just didn't look right.  And I didn't know where to start digging to sort it out on my my own, so I used the forum.  Really appreciate your answer.  Thanks.

Navigation

[0] Message Index

Go to full version