UnityWebRequest leaking memory.

Would someone try this program? Please tell me If it leaks memory or not.

using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public class MemoryLeak : MonoBehaviour
{
	public string _Url = "https://www.google.com/";

	public int _LoopCnt;

	void Start()
	{
		Loop();
	}

	void Loop()
	{
		StartCoroutine(Send());
	}

	IEnumerator Send()
	{
		using (UnityWebRequest request = UnityWebRequest.Get(_Url))
		{
			yield return request.SendWebRequest();
		}

		_LoopCnt++;
		Loop();
	}
}

On Unity 2018.2.13f1 (64-bit), this program will crash on windows. Looks like leaking memory as I observed windows task manager.

On Unity 2018.1.9f2 (64-bit) it will not leak memory.

I found that newer than Unity 2018.1.9f2 (64-bit) it will leak memory.

I reported this as bug to Unity team but they say they can not reproduce it.

Is this happening only on my environment?

I am using Japanese Windows 10 home.

CPU AMD Ryzen 5 1600X.

@ramd21 did you find a solution?

I have a big problem which aligns well and appears to correspond exactly to the following Mono leak.

I use await/async with DynamoDB queries and the result is 1000s of system.byte arrays hanging around uncollected by the GC. String allocations seem to be growing in a correlated way too. Over a day or two i’m losing 100mb or more.

Well it’s not clear if the issue is the web request. You should never constantly make a coroutine calling itself. A coroutine requires memory and need to be garbage collected as well. Is that your actual testing code? You don’t do anything with the returned data?

Instead of making your coroutine calling itself, you should simply use a loop:

IEnumerator Send()
{
    while (true)
    {
        using (UnityWebRequest request = UnityWebRequest.Get(_Url))
        {
            yield return request.SendWebRequest();
        }
        _LoopCnt++;
    }
}

This has the exact same effect but without any nested coroutines.