Do recursive coroutines leak memory?

I’ve got a function that needs to run roughly every half second, so naturally I’m looking at a coroutine.

I’m just curious, is this sufficient, or will this cause the stack frame associated with this coroutine to get bigger and bigger over time?

void Start ()
{
	StartCoroutine(LookForSquidward());
}

IEnumerator LookForSquidward()
{
	yield return new WaitForSeconds(0.5f);
	if (IsThisPatrick()) {
		Debug.Log("Yes, this is Squidward.");
	} else {
		Debug.Log ("No, this is Patrick.");
	}
	StartCoroutine(LookForSquidward());
}

I know the approach of using a while loop instead of a recursive StartCoroutine would unambiguously not grow the stack frame, but I’d like to know the specifics of how this approach works (or doesn’t).

This way this will work because the coroutine is not stricly recursive: each coroutine overlaps the next one for one frame. To be recursive, and hence have possible issues, you would need to do that instead:

// FAULTY CODE. DON'T DO THIS. 
void Start ()
{
    StartCoroutine(LookForSquidward());
}

IEnumerator LookForSquidward()
{
    yield return new WaitForSeconds(0.5f);
    if (IsThisPatrick()) {
       Debug.Log("Yes, this is Squidward.");
    } else {
       Debug.Log ("No, this is Patrick.");
    }
    yield return StartCoroutine(LookForSquidward());
}

But IMHO, using loops is a better approach. Still, your code works and doesn’t raise any recursive issue.