Luke Posted July 31, 2020 Posted July 31, 2020 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 Quote
Stas Posted July 31, 2020 Posted July 31, 2020 (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 July 31, 2020 by Stas 1 Quote
Omar Zelaya Posted August 1, 2020 Posted August 1, 2020 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 2 Quote
Omar Zelaya Posted August 1, 2020 Posted August 1, 2020 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; 2 Quote
Luke Posted August 1, 2020 Author Posted August 1, 2020 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. V_20200801_131036.mp4 Quote
Omar Zelaya Posted August 1, 2020 Posted August 1, 2020 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); 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.