diff --git a/src/curlEngine.d b/src/curlEngine.d index 7decae7b..f4c4b6c4 100644 --- a/src/curlEngine.d +++ b/src/curlEngine.d @@ -161,7 +161,7 @@ class CurlResponse { class CurlEngine { __gshared static CurlEngine[] curlEnginePool; // __gshared is used for thread-shared static variables - + HTTP http; bool keepAlive; ulong dnsTimeout; @@ -211,8 +211,8 @@ class CurlEngine { } } } - - static void releaseAllCurlInstances() { + + static void releaseAllCurlInstances() { synchronized (CurlEngine.classinfo) { // Safely iterate and clean up each CurlEngine instance foreach (CurlEngine curlEngine; curlEnginePool) { @@ -230,7 +230,12 @@ class CurlEngine { // Clear the array after all instances have been handled curlEnginePool.length = 0; // More explicit than curlEnginePool = []; } - // Destroy curlEnginePool, set to null + } + + static void destroyAllCurlInstances() { + // Release all 'curl' instances + releaseAllCurlInstances(); + // Destroy curlEnginePool, set to null object.destroy(curlEnginePool); curlEnginePool = null; } diff --git a/src/log.d b/src/log.d index 350c24fe..0648f952 100644 --- a/src/log.d +++ b/src/log.d @@ -107,8 +107,9 @@ class LogBuffer { // Use dnotify's functionality for GUI notifications, if GUI notifications is enabled version(Notifications) { try { - auto n = new Notification("OneDrive Client for Linux", message, "IGNORED"); - //n.timeout = 5; + auto n = new Notification("OneDrive Client", message, "IGNORED"); + // Show notification for 10 seconds + n.timeout = 10; n.show(); } catch (NotificationError e) { sendGUINotification = false; diff --git a/src/main.d b/src/main.d index 101e617c..a01c504e 100644 --- a/src/main.d +++ b/src/main.d @@ -994,13 +994,17 @@ int main(string[] cliArgs) { addLogEntry("End Monitor Loop Time: " ~ to!string(endFunctionProcessingTime), ["debug"]); addLogEntry("Elapsed Monitor Loop Processing Time: " ~ to!string((endFunctionProcessingTime - startFunctionProcessingTime)), ["debug"]); - // Display memory details before cleanup + // Release all the curl instances used during this loop + // New curl instances will be established on next loop + CurlEngine.releaseAllCurlInstances(); + + // Display memory details before garbage collection if (displayMemoryUsage) displayMemoryUsagePreGC(); - // Perform Garbage Cleanup + // Perform Garbage Collection GC.collect(); // Return free memory to the OS GC.minimize(); - // Display memory details after cleanup + // Display memory details after garbage collection if (displayMemoryUsage) displayMemoryUsagePostGC(); // Log that this loop is complete @@ -1405,8 +1409,8 @@ void performSynchronisedExitProcess(string scopeCaller = null) { shutdownFilesystemMonitor(); // Shutdown the database shutdownDatabase(); - // Shutdown 'curl' instances - shutdownCurlInstances(); + // Destroy all 'curl' instances + destroyCurlInstances(); // Shutdown the application configuration objects shutdownAppConfig(); @@ -1481,8 +1485,8 @@ void shutdownAppConfig() { } } -void shutdownCurlInstances() { - CurlEngine.releaseAllCurlInstances(); +void destroyCurlInstances() { + CurlEngine.destroyAllCurlInstances(); } void shutdownApplicationLogging() { diff --git a/src/util.d b/src/util.d index 9229b51e..669ee397 100644 --- a/src/util.d +++ b/src/util.d @@ -202,7 +202,7 @@ Regex!char wild2regex(const(char)[] pattern) { } // Test Internet access to Microsoft OneDrive -bool testInternetReachability(ApplicationConfig appConfig) { +bool testInternetReachabilityCurlPool(ApplicationConfig appConfig) { CurlEngine curlEngine; bool result = false; try { @@ -240,7 +240,7 @@ bool testInternetReachability(ApplicationConfig appConfig) { } // Test Internet access to Microsoft OneDrive using a simple HTTP HEAD request -bool testInternetReachabilityAlternate(ApplicationConfig appConfig) { +bool testInternetReachability(ApplicationConfig appConfig) { auto http = HTTP(); http.url = "https://login.microsoftonline.com"; @@ -1114,26 +1114,25 @@ string generateAlphanumericString(size_t length = 16) { void displayMemoryUsagePreGC() { // Display memory usage writeln(); - writeln("Memory Usage pre GC (KB)"); - writeln("------------------------"); + writeln("Memory Usage PRE Garbage Collection (KB)"); + writeln("-----------------------------------------"); writeMemoryStats(); writeln(); } void displayMemoryUsagePostGC() { // Display memory usage - writeln(); - writeln("Memory Usage post GC (KB)"); - writeln("-------------------------"); + writeln("Memory Usage POST Garbage Collection (KB)"); + writeln("-----------------------------------------"); writeMemoryStats(); writeln(); } void writeMemoryStats() { // write memory stats - writeln("memory usedSize = ", (GC.stats.usedSize/1024)); - writeln("memory freeSize = ", (GC.stats.freeSize/1024)); - writeln("memory allocatedInCurrentThread = ", (GC.stats.allocatedInCurrentThread/1024)); + writeln("memory usedSize = ", (GC.stats.usedSize/1024)); // number of used bytes on the GC heap (might only get updated after a collection) + writeln("memory freeSize = ", (GC.stats.freeSize/1024)); // number of free bytes on the GC heap (might only get updated after a collection) + writeln("memory allocatedInCurrentThread = ", (GC.stats.allocatedInCurrentThread/1024)); // number of bytes allocated for current thread since program start } // Return the username of the UID running the 'onedrive' process