Reputation: 55
I'm opening a new form. It's getting slower each time when opening it.I try FormClose event FreeAndnil, Free, Release, DisposeOf but not solution. I've added a standby timer:
Button1 first Click, After Form 2 show 0,18 Second
Button1 Second Click, After Form 2 show 0,20 Second
Button1 Third Click, After Form 2 show 0,23 Second
Button1 fourth Click, After Form 2 show 0,28 Second . . .
Button1 xxxx Click, After Form 2 show 6,30 Second
//Form1 Button1 Click
Application.CreateForm(TFrom2,Form2);
Form2.Show;
//Form2 OnCLose
//i try
//FreeAndNil, Free, Relsease,DisposeOf ...
How to solve this? Sample Project Source : https://www.dropbox.com/s/yeqpizr6rfo6254/LeakProblem.rar
Try 20-30 times Click "Form2 Show Button" See increase wait time in memo.
Upvotes: 1
Views: 1813
Reputation: 1112
Well, I messed around with your project a little and got it working, but there's a lot of things that you do differently than how I normally program.
For starters, when disposing of a form in mobile you want to use .DisposeOf, not FreeAndNil. See this link, especially:
there are scenarios when you need to execute the destructor code right away, regardless of the fact that there might be other pending references to the object. [...] the new compiler introduces a dispose pattern:
MyObject.DisposeOf
;
Another thing I noticed is that your Unit3 creates Form4. But then you have Unit4 accessing the memo in Unit3. I hope that's just for demo purposes as I don't think that sort of design is suggested.
So, short summary of how I got it to work: I set up a TNotifyEvent
in Form4 for when it is finished:
procedure TForm4.Button1Click(Sender: TObject);
begin
if assigned(FOnCloseEvent) then
FOnCloseEvent(Self);
end;
In Uni3, I setup a handler when the form is created:
MyForm.OnCloseEvent := CloseEvent;
The event triggers this code:
procedure TForm3.CloseEvent(Sender: TObject);
begin
if assigned(MyForm) then
MyForm.DisposeOf;
end;
I also made MyForm
a private object of TForm3
as opposed to local variable.
With these changes I can hit show and close as long as I want and the form will always show quickly. There could be better ways to do this, if there are let me know!
Upvotes: 1