Skip to content

Commit

Permalink
[Feature] Clear internal icon cache if too big (#207), version 1.0.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofknecht committed Oct 6, 2021
1 parent de57fce commit d669b15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Business/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ void StartLoadMenu(RowData rowData)
{
loadingRowData = rowData;

Menu menuLoading = menus[rowData.MenuLevel + 1];
if (menuLoading != null && menuLoading.IsLoadingMenu)
{
CloseMenu(rowData.MenuLevel + 1);
}

CreateAndShowLoadingMenu(rowData);
void CreateAndShowLoadingMenu(RowData rowData)
{
Expand Down Expand Up @@ -177,7 +171,8 @@ void LoadSubMenuCompleted(object senderCompleted, RunWorkerCompletedEventArgs e)
Menu menuLoading = menus[menuData.Level];
if (menuLoading != null && menuLoading.IsLoadingMenu)
{
CloseMenu(menuData.Level);
menuLoading.HideWithFade();
menus[menuLoading.Level] = null;
}

if (menuData.Validity != MenuDataValidity.AbortedOrUnknown &&
Expand Down Expand Up @@ -773,6 +768,12 @@ private void MenuVisibleChanged(object sender, EventArgs e)
if (!AsEnumerable.Any(m => m.Visible))
{
openCloseState = OpenCloseState.Default;

if (IconReader.ClearIfCacheTooBig())
{
GC.Collect();
MainPreload();
}
}
}

Expand Down Expand Up @@ -920,7 +921,6 @@ private void HideOldMenu(Menu menuToShow, bool keepOrSetIsMenuOpen = false)
foreach (Menu menuToClose in menus.Where(
m => m != null && m.Level > menuPrevious.Level))
{
menuToClose.VisibleChanged += MenuVisibleChanged;
menuToClose.HideWithFade();
menus[menuToClose.Level] = null;
}
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.20.1")]
[assembly: AssemblyFileVersion("1.0.20.1")]
[assembly: AssemblyVersion("1.0.20.2")]
[assembly: AssemblyFileVersion("1.0.20.2")]
13 changes: 13 additions & 0 deletions Utilities/File/IconReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public static void Dispose()
}
}

internal static bool ClearIfCacheTooBig()
{
bool cleared = false;
if (DictIconCache.Count > 200)
{
Dispose();
DictIconCache.Clear();
cleared = true;
}

return cleared;
}

public static Icon GetFileIconWithCache(string filePath, bool linkOverlay, bool updateIconInBackground, out bool loading)
{
Icon icon = null;
Expand Down

0 comments on commit d669b15

Please sign in to comment.