Use shared singleton HttpClient instance to prevent memory leak from creating short-lived HttpClient instances without disposing them. (A singleton HttpClient instance is the recommended use pattern per Microsoft's documentation.)
Optimize Regex usage to unnecessary object recreation (Regex creation is expensive and should be reused whenever practical).
In my testing, memory usage has been very stable after this fix. Prior to the fix I could observe the memory ticking up and staying there after every HttpClient instance was created. I haven't tested this for an extended period of time but I believe this will mitigate this specific memory leak.
Regex
creation is expensive and should be reused whenever practical).In my testing, memory usage has been very stable after this fix. Prior to the fix I could observe the memory ticking up and staying there after every HttpClient instance was created. I haven't tested this for an extended period of time but I believe this will mitigate this specific memory leak.