From: Jiyun Yang Date: Thu, 14 Mar 2024 04:22:05 +0000 (+0900) Subject: [NUI] WeakEvent : Improve clean-up condition X-Git-Tag: submit/tizen_7.0/20240314.150747~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3ed6900b14812feabb670e45562ec1ed2616c23;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] WeakEvent : Improve clean-up condition Signed-off-by: Jiyun Yang --- diff --git a/src/Tizen.NUI/src/internal/Common/WeakEvent.cs b/src/Tizen.NUI/src/internal/Common/WeakEvent.cs index 5a1e9e868..1b12cef4b 100755 --- a/src/Tizen.NUI/src/internal/Common/WeakEvent.cs +++ b/src/Tizen.NUI/src/internal/Common/WeakEvent.cs @@ -23,8 +23,9 @@ namespace Tizen.NUI { internal class WeakEvent where T : Delegate { - private const int cleanUpThreshold = 100; // Experimetal constant - private int cleanUpCount = 0; + private const int addThreshold = 1000; // Experimetal constant + private const int listLengthThreshold = 1000; // Experimetal constant + private int cleanUpAddCount = 0; private List> handlers = new List>(); protected int Count => handlers.Count; @@ -46,8 +47,6 @@ namespace Tizen.NUI handlers.RemoveAt(lastIndex); OnCountDicreased(); } - - CleanUpDeadHandlersIfNeeds(); } public void Invoke(object sender, EventArgs args) @@ -74,7 +73,9 @@ namespace Tizen.NUI private void CleanUpDeadHandlersIfNeeds() { - if (++cleanUpCount == cleanUpThreshold) + // Once the list count exceed 'listLengthThreshold', do the clean-up every 'addThreshold' add operations. + // When list count go below `listLengthThreshold` before clean-up, pause operation counting. + if (handlers.Count > listLengthThreshold && ++cleanUpAddCount > addThreshold) { CleanUpDeadHandlers(); } @@ -82,7 +83,7 @@ namespace Tizen.NUI private void CleanUpDeadHandlers() { - cleanUpCount = 0; + cleanUpAddCount = 0; int count = handlers.Count; handlers.RemoveAll(item => !item.IsAlive); if (count > handlers.Count) OnCountDicreased();