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).