Atozed Forums

Full Version: Clear datas when switch forms
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have UIWServerControllerBaseConfig define two forms:

IWExceptionRenderer.SetExceptionRendererClass(TIWExceptionRendererEx);
 if FLock<>nil then FreeAndNil(FLock);
 FLock:= TCriticalSection.Create;
THandlers.Add('', 'Form1', TContentForm.Create(TForm1)); http://localhost/form1 (first load)
THandlers.Add('', 'Form2', TContentForm.Create(TForm2)); http://localhost/form2



In UserSesssion i have define procedures LoadDatas/ClearDatas with my TDatas. Both Forms used this procedures.

If switch Form2 then i want ClearDatas in Form1? If i dont, i get memory leaks from Form1, if destroy Usersession! Who Release!
Each form should be responsible for its own clean up. That's what encapsulation means in OOP.

Clear the data when the form is destroyed and you won't get any leak.
BTW, seems that you are creating a TCriticalSection in your ServerController... Not sure if it is related to the handlers or not, but content handlers don't need it.
(02-16-2021, 07:02 PM)Alexandre Machado Wrote: [ -> ]BTW, seems that you are creating a TCriticalSection in your ServerController... Not sure if it is related to the handlers or not, but content handlers don't need it.

Shows this is cause for my memory leaks:

!!! TIWAppForm(WebApplication.ActiveForm).Release; !!! 
WebApplication.SetActiveForm(TLogOut.Create(WebApplication));

This line removed!Ok
(02-16-2021, 07:02 PM)Alexandre Machado Wrote: [ -> ]BTW, seems that you are creating a TCriticalSection in your ServerController... Not sure if it is related to the handlers or not, but content handlers don't need it.

You cann see solution memory leaks!

I woudl like, when i leave page http://localhost/form1 -> http://localhost/form2 -> cleardatas in form1

Not when if usersession.destroy -> form1.destroy? In VCL Forms is this OnClose event? Recipe? Smile