yangyxd / FMXUI

FMX跨平台基础UI库
MIT License
261 stars 96 forks source link

Memory Leak On TToastManager In Delphi 11.3.1 #59

Closed stackerliew closed 1 year ago

stackerliew commented 1 year ago

As title.

KngStr commented 1 year ago

We need more infomation

stackerliew commented 1 year ago

Here is the screenshot. MemoryLeak

stackerliew commented 1 year ago

Same source no memory leak in D10.3 and D10.4.2

stackerliew commented 1 year ago

Here is my code. I only use one third party component here, which is TToastManager. `unit utFMXClock;

interface

uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects, FMX.StdCtrls, FMX.Effects, FMX.Controls.Presentation, FMX.Layouts, FMX.Colors, UI.Toast, FMX.Ani;

type TFMXClockForm = class(TForm) FMXClockTimer: TTimer; FMXClockStyleBook: TStyleBook; FMXClockToastManager: TToastManager; FMXClockToolBar: TToolBar; FMXClockToolBarTitleLabel: TLabel; FMXClockToolBarShadowEffect: TShadowEffect; FMXClockContentLayout: TLayout; FMXClockContentScreenLockLayout: TLayout; FMXClockScreenLockRectangle: TRectangle; FMXClockToolBarScreenLockSwitch: TSwitch; FMXClockToolBarScreenLockSwitchLabel: TLabel; FMXClockRectangle: TRectangle; FMXClockContentFacePanel: TPanel; FMXClockContentFaceCircle: TCircle; FMXClockElevenLayout: TLayout; FMXClockElevenText: TText; FMXClockEightLayout: TLayout; FMXClockEightText: TText; FMXClockFiveLayout: TLayout; FMXClockFiveText: TText; FMXClockFourLayout: TLayout; FMXClockFourText: TText; FMXClockNineLayout: TLayout; FMXClockNineText: TText; FMXClockOneLayout: TLayout; FMXClockOneText: TText; FMXClockSevenLayout: TLayout; FMXClockSevenText: TText; FMXClockSixLayout: TLayout; FMXClockSixText: TText; FMXClockTenLayout: TLayout; FMXClockTenText: TText; FMXClockThreeLayout: TLayout; FMXClockThreeText: TText; FMXClockTwelveLayout: TLayout; FMXClockTwelveText: TText; FMXClockTwoLayout: TLayout; FMXClockTwoText: TText; FMXClockHourRoundRect: TRoundRect; FMXClockHourRoundRectShadowEffect: TShadowEffect; FMXClockMinRoundRect: TRoundRect; FMXClockMinRoundRectShadowEffect: TShadowEffect; FMXClockSecondsRoundRect: TRoundRect; FMXClockSecondsRoundRectShadowEffect: TShadowEffect; FMXClockFaceCircleShadowEffect: TShadowEffect; FMXClockFaceCentreCircle: TCircle; FMXClockFaceCentreCircleShadowEffect: TShadowEffect; FMXClockContentFaceBackgroundCircle: TCircle; FMXClockContentFaceBackgroundFloatAnimation: TFloatAnimation; FMXClockContentRectangle: TRectangle; FMXClockToolBarRectangle: TRectangle; FMXClockContentOpacityFloatAnimation: TFloatAnimation; FMXClockDarkStyleBook: TStyleBook; procedure FormCreate(Sender: TObject); procedure FMXClockTimerTimer(Sender: TObject); procedure FMXClockToolBarScreenLockSwitchSwitch(Sender: TObject); procedure FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); procedure FormResize(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } FFMXClockLastExitTick: Cardinal; (* ** ) function GetFMXClockLastExitTick: Cardinal; ( ** *) procedure SetFMXClockLastExitTick(const Value: Cardinal); public { Public declarations } property FMXClockLastExitTick: Cardinal read GetFMXClockLastExitTick write SetFMXClockLastExitTick; end;

var FMXClockForm: TFMXClockForm;

implementation

uses System.Math, FMX.Platform, FMX.VirtualKeyboard {$IFDEF ANDROID}, FMX.StatusBar, FMX.Helpers.Android, Androidapi.Helpers, Androidapi.Jni.GraphicsContentViewText, Androidapi.Jni.App {$ENDIF};

{$R *.fmx}

procedure TFMXClockForm.FormCreate(Sender: TObject); begin {$IFDEF ANDROID} // TAndroidHelper.Activity.getWindow.setFlags(TJWindowManager_LayoutParams.JavaClass.FLAG_LAYOUT_NO_LIMITS, TJWindowManager_LayoutParams.JavaClass.FLAG_LAYOUT_NO_LIMITS); // StatusBarSetColor(FMXClockForm.FMXClockToolBar.TintColor); {$ENDIF} end;

procedure TFMXClockForm.FMXClockTimerTimer(Sender: TObject); begin FMXClockHourRoundRect.RotationAngle := (30 StrToInt(FormatDateTime('h', now))) + (6 (StrToInt(FormatDateTime('n', now)) / 12)); FMXClockMinRoundRect.RotationAngle := 6 StrToInt(FormatDateTime('n', now)); FMXClockSecondsRoundRect.RotationAngle := 6 StrToInt(FormatDateTime('ss', now)); end;

procedure TFMXClockForm.FMXClockToolBarScreenLockSwitchSwitch(Sender: TObject); begin case (Sender as TSwitch).IsChecked of True: begin {$IFDEF ANDROID} CallInUIThreadAndWaitFinishing( procedure begin TAndroidHelper.Activity.getWindow.addFlags(TJWindowManager_LayoutParams.JavaClass.FLAG_KEEP_SCREEN_ON); FMXClockToastManager.Toast('Screen Lock Disabled'); end); {$ENDIF} {$IFDEF MSWINDOWS} FMXClockToastManager.Toast('Unsupported Platform Feature'); {$ENDIF} end; False: begin {$IFDEF ANDROID} CallInUIThreadAndWaitFinishing( procedure begin TAndroidHelper.Activity.getWindow.clearFlags(TJWindowManager_LayoutParams.JavaClass.FLAG_KEEP_SCREEN_ON); FMXClockToastManager.Toast('Screen Lock Enabled'); end); {$ENDIF} {$IFDEF MSWINDOWS} FMXClockToastManager.Toast('Unsupported Platform Feature'); {$ENDIF} end; end; end;

procedure TFMXClockForm.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); var FService: IFMXVirtualKeyboardService; begin if (Key = vkHardwareBack) or (Key = vkEscape) then begin TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService)); if not((FService <> nil) and (TVirtualKeyboardState.Visible in FService.VirtualKeyboardState)) then begin Key := 0;

  if ((TThread.GetTickCount - FMXClockLastExitTick) >= 2000) then
  begin
    FMXClockLastExitTick := TThread.GetTickCount;
    FMXClockToastManager.Toast('Press BACK/Escape Again To Quit');
  end
  else
    Close;
end;

end; end;

procedure TFMXClockForm.FormResize(Sender: TObject); begin with FMXClockContentFaceCircle do begin Align := TAlignLayout.Client;

FMXClockTwelveLayout.Height := Min(Height, Width);
FMXClockOneLayout.Height := Min(Height, Width);
FMXClockTwoLayout.Height := Min(Height, Width);
FMXClockThreeLayout.Height := Min(Height, Width);
FMXClockFourLayout.Height := Min(Height, Width);
FMXClockFiveLayout.Height := Min(Height, Width);
FMXClockSixLayout.Height := Min(Height, Width);
FMXClockSevenLayout.Height := Min(Height, Width);
FMXClockEightLayout.Height := Min(Height, Width);
FMXClockNineLayout.Height := Min(Height, Width);
FMXClockTenLayout.Height := Min(Height, Width);
FMXClockElevenLayout.Height := Min(Height, Width);

FMXClockHourRoundRect.Height := Min(Height, Width) * 0.65 / 2;
FMXClockMinRoundRect.Height := Min(Height, Width) * 0.8 / 2;
FMXClockSecondsRoundRect.Height := Min(Height, Width) * 0.8 / 2;

FMXClockHourRoundRect.Position.X := (FMXClockContentFaceCircle.Width - FMXClockHourRoundRect.Width) / 2;
FMXClockMinRoundRect.Position.X := (FMXClockContentFaceCircle.Width - FMXClockMinRoundRect.Width) / 2;
FMXClockSecondsRoundRect.Position.X := (FMXClockContentFaceCircle.Width - FMXClockSecondsRoundRect.Width) / 2;

FMXClockHourRoundRect.Position.Y := (FMXClockContentFaceCircle.Height / 2) - FMXClockHourRoundRect.Height;
FMXClockMinRoundRect.Position.Y := (FMXClockContentFaceCircle.Height / 2) - FMXClockMinRoundRect.Height;
FMXClockSecondsRoundRect.Position.Y := (FMXClockContentFaceCircle.Height / 2) - FMXClockSecondsRoundRect.Height;

end; end;

procedure TFMXClockForm.FormShow(Sender: TObject); begin with FMXClockContentFaceCircle do begin Align := TAlignLayout.Client;

FMXClockTwelveLayout.Height := Min(Height, Width);
FMXClockOneLayout.Height := Min(Height, Width);
FMXClockTwoLayout.Height := Min(Height, Width);
FMXClockThreeLayout.Height := Min(Height, Width);
FMXClockFourLayout.Height := Min(Height, Width);
FMXClockFiveLayout.Height := Min(Height, Width);
FMXClockSixLayout.Height := Min(Height, Width);
FMXClockSevenLayout.Height := Min(Height, Width);
FMXClockEightLayout.Height := Min(Height, Width);
FMXClockNineLayout.Height := Min(Height, Width);
FMXClockTenLayout.Height := Min(Height, Width);
FMXClockElevenLayout.Height := Min(Height, Width);

FMXClockHourRoundRect.Height := Min(Height, Width) * 0.65 / 2;
FMXClockMinRoundRect.Height := Min(Height, Width) * 0.8 / 2;
FMXClockSecondsRoundRect.Height := Min(Height, Width) * 0.8 / 2;

FMXClockHourRoundRect.Position.X := (FMXClockContentFaceCircle.Width - FMXClockHourRoundRect.Width) / 2;
FMXClockMinRoundRect.Position.X := (FMXClockContentFaceCircle.Width - FMXClockMinRoundRect.Width) / 2;
FMXClockSecondsRoundRect.Position.X := (FMXClockContentFaceCircle.Width - FMXClockSecondsRoundRect.Width) / 2;

FMXClockHourRoundRect.Position.Y := (FMXClockContentFaceCircle.Height / 2) - FMXClockHourRoundRect.Height;
FMXClockMinRoundRect.Position.Y := (FMXClockContentFaceCircle.Height / 2) - FMXClockMinRoundRect.Height;
FMXClockSecondsRoundRect.Position.Y := (FMXClockContentFaceCircle.Height / 2) - FMXClockSecondsRoundRect.Height;

end; end;

function TFMXClockForm.GetFMXClockLastExitTick: Cardinal; begin Result := FFMXClockLastExitTick; end;

procedure TFMXClockForm.SetFMXClockLastExitTick(const Value: Cardinal); begin if FFMXClockLastExitTick <> Value then FFMXClockLastExitTick := Value; end;

initialization

ReportMemoryLeaksOnShutdown := True;

finalization

end. `

stackerliew commented 1 year ago

It looks like not TToastManager's problem.

KngStr commented 1 year ago

@stackerliew Did you find the problem? Should this issue be closed?

stackerliew commented 1 year ago

Sorry, please close the issue.

從 Windows 的郵件https://go.microsoft.com/fwlink/?LinkId=550986傳送

寄件者: @.> 傳送時間: 2023年6月18日 上午 11:01 收件者: @.> 副本: @.>; @.> 主旨: Re: [yangyxd/FMXUI] Memory Leak On TToastManager In Delphi 11.3.1 (Issue #59)

@stackerliewhttps://github.com/stackerliew Did find the problem? Should this issue be closed?

— Reply to this email directly, view it on GitHubhttps://github.com/yangyxd/FMXUI/issues/59#issuecomment-1595934960, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AJAYLNYXE5KZ365AT746ZC3XLZVQRANCNFSM6AAAAAAX4HSCCQ. You are receiving this because you were mentioned.Message ID: @.***>