From cd4fe3d0a19799ec9a4d61fdd67708a5017d6f07 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 15 Dec 2021 09:02:49 -0600 Subject: use CollectGarbage to collect garbage --- src/slskd/Core/API/Controllers/ApplicationController.cs | 4 +--- src/slskd/Search/SearchService.cs | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index 501f8a9c..19360fe1 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -19,7 +19,6 @@ namespace slskd.Core.API { using System; using System.Diagnostics; - using System.Runtime; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -128,8 +127,7 @@ namespace slskd.Core.API [Authorize] public IActionResult CollectGarbage() { - GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; - GC.Collect(2, GCCollectionMode.Forced, blocking: false, compacting: true); + Application.CollectGarbage(); return Ok(); } diff --git a/src/slskd/Search/SearchService.cs b/src/slskd/Search/SearchService.cs index e529f738..b934e86b 100644 --- a/src/slskd/Search/SearchService.cs +++ b/src/slskd/Search/SearchService.cs @@ -45,16 +45,19 @@ namespace slskd.Search /// /// /// + /// /// The database context to use. /// The logger. public SearchService( IOptionsMonitor optionsMonitor, ISoulseekClient soulseekClient, + IApplication application, IDbContextFactory contextFactory, ILogger log) { OptionsMonitor = optionsMonitor; Client = soulseekClient; + Application = application; ContextFactory = contextFactory; Log = log; } @@ -63,6 +66,7 @@ namespace slskd.Search = new ConcurrentDictionary(); private IOptionsMonitor OptionsMonitor { get; } + private IApplication Application { get; } private ISoulseekClient Client { get; } private IDbContextFactory ContextFactory { get; } private ILogger Log { get; set; } @@ -130,6 +134,7 @@ namespace slskd.Search finally { CancellationTokens.TryRemove(id, out _); + Application.CollectGarbage(); } } -- cgit v1.2.3