StartCoroutine memory leak

Hi everybody, I have a problem with my project on iOS device, I am using:

StartCoroutine(DelayFunc(0.1f));

public IEnumerator DelayFunc(float _t){
	yield return new WaitForSeconds(_t);
 
}

And every time I run this coroutine I have “Used heap” is growing up in xcode console profiler. How to resolve this memory leak?

You can simply run StartCoroutine(DelayFunc(0.1f)); in loop over 10000 times and you’ll see garbage collector running and fps dropping down:(

Does it go down when you call System.GC.Collect(); ?

It’s known that StartCoroutine allocates memory on the heap, which will be reclaimed when the garbage collector runs. Check out this article on Gamasutra which also mentions this: Game Platforms recent news | Game Developer

Its go down when GC runs, but at this time fps goes down too, I’d like to write project with minmum GC events.

It’s not a memory leak. A memory leak occurs when a program allocates memory and doesn’t release it when you quit.

–Eric

wow can you confirm that its safe to use corroutines for memory? i used it a lot each seconds for anim states

So, it is very good practice to develop project for iOS devices:) My advice, guys, use profiler at the beginning, otherwise you’ll get surprise at the end and will refactoring all you code!!!

gametr4x, thank you for link!

Changchun, not sure that you will get project perfectly well at the end, turn on unity profiller for ios and take a look at “used heap” and garbage collector:)

yea problem is i use free version, anyway if i change scene, the CG is reset?

I am using this version too, but when you compile project for xcode, there is iPhone_profiller.h file has string #define ENABLE_INTERNAL_PROFILER 0
Change it to #define ENABLE_INTERNAL_PROFILER 1 and run project. You will see a lot of interesting info in console, also you can check for GC running between you scenes. Unity - Manual: Measuring performance with the built-in profiler