Jump to content
Sign in to follow this  
Luke

TfgForm : Free and Nil

Recommended Posts

Hi Guys,
i know that this isn't a specific question about FGX but i try to ask you.

I attach a little demo source code that i'm writing.
I'm using a DrawerLayout and i show differents forms in the Content.
All works perfectly.

When i've to destroy the Form i've seen in your Demo that i've to write the rows below :

      MyForm.Parent := nil;
      FreeAndNil(MyForm);

If i do that, it works perfectly, but, if i comment the "MyForm.Parent := nil" and i call only FreeAndNil, for Delphi MyForm is destroyed but for Android no, because i can see it in my content and i can work with it.


I know that Java use the Garbage Collector so i'm worried about "Free Form Memory".

In Delphi, if i seen MyForm = nil i will create it another time so, how many MyForm i've in memory ?

I've a second question, not so important, but i try to ask:
My TFrameUsers load data from a Rest Service into a CollectionView.
I know that i can write better code, but i see that if i try to scroll the CollectionView, it is slow in the first 2 seconds, and then it is very fast!
I can't understand why it is slow at the beginning...
I'm sure that all data is available so, do you have any idea in "Why it is slow at the begin?"
Many Thanks guys.
 

Demo01.zip

Share this post


Link to post
Share on other sites
Posted (edited)

Hello, imho in new version Delphi, it have own garbage collector, and you don't worry about memory leaks, about you second question, can you try load you rest data locally from inner json and compare time for loading

Thanks 

Edited by Stas
  • Like 1

Share this post


Link to post
Share on other sites

Hi,

Rad Studio 10.3 memory manager uses arc on mobile, so you kind of shouldnt dont worry about memory release. On 10.4 on mobile now use standard memory model(not more arc) and you SHOULD be aware to release memory.

About second question, not quite familiar with TRestRequest class and ExecuteAsync Method, In my own experience i always do any intenert request using Threads with no problems(no delays on main thread).

I would suggest to use Threads to request data from the internet. I'm developing a App that laods data and images from a rest server with no delay on the app using threads.

Hope it Helps,

Omar Zelaya

 

  • Like 2

Share this post


Link to post
Share on other sites

Hi

Maybe this help,

procedure CustomThread(
  AOnStart,
  AOnProcess,
  AOnComplete : TProc;
  AOnError: TProcedureExcept;
  ADoCompletWithError: Boolean = True);
var
  LThread : TThread;
begin
  LThread :=
    TThread.CreateAnonymousThread(
      procedure ()
      var
        LDoComplete : Boolean;
      begin
        try
          try
            //OnStart
            LDoComplete := True;
            if Assigned(AOnStart) then
            begin
              TThread.Synchronize(
                TThread.CurrentThread,
                procedure ()
                begin
                  AOnStart;
                end
              );
            end;

            //OnProcess
            if Assigned(AOnProcess) then
              AOnProcess;

          //OnError
          except on E:Exception do
            begin
              LDoComplete := ADoCompletWithError;
              if Assigned(AOnError) then
              begin
                TThread.Synchronize(
                  TThread.CurrentThread,
                  procedure ()
                  begin
                    AOnError(E.Message);
                  end
                );
              end;

            end;
          end;
        finally
          //OnComplete
          if Assigned(AOnComplete) then
          begin
            TThread.Synchronize(
              TThread.CurrentThread,
              procedure ()
              begin
                AOnComplete;
              end
            );
          end;
        end;
      end
    );

  LThread.FreeOnTerminate := True;
  LThread.Start;
end;

  • Like 2

Share this post


Link to post
Share on other sites

Hi Omar,
Many thanks for your support.
I will check your source code for a better management.
However in my case the problem is not read data.
I attach a small video.
I can wait 20 or 30 seconds before start the scolling and data is already stored in my collection.
As you can see the lag is very very small and it isn't a problem but i'm trying to get best practice methods and discover what can't be solved and what is a limit.
Many Thanks.
 

Share this post


Link to post
Share on other sites

Hi,

usage of thread method.

CustomThread(/// OnStart
                               procedure ()
                               begin
                                 // show some kind of wait message to user
                               end,
                               /// OnProcess
                               procedure ()
                               begin
                                 // request data
                               end,
                               /// On Complete
                               procedure ()
                               begin
                                 /// show end data request
                               end,
                               // On Error
                               procedure ()
                               begin
                                 /// show error on data request
                               end);

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Similar Content

    • By gats
      hello
      I tried changing the background color on the systemstatusbar, but it didn't have the effect after it was compiled to a device with the results fixed with the original color of the device's theme. Is my method incorrect?

      thank you
    • By Stas
      Здравствуйте, странная ситуация.
      Имеем
      MainForm TfgNavigatorBar TfgCollectionView SecondForm TfgNavigatorBar TfgCardPanel У всех относительное расположение.
      У TfgCollectionView есть событие onTapItem, по которому вызывается вторая форма.
      Так вот при тапе на TfgCardPanel второй формы, радостно срабатывает событие onTapItem,
      Важный нюанс TfgCardPanel должно находиться прямо под TfgNavigatorBar
      Спасибо
       
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...