This is both a concern I want to share with other people and a question if its correct.
While looking into my Heap memory usage to help reduce my garbage collection churn I noticed that waitforseconds causes a heap increase every few random seconds. also the amount it causes to increase isnt consistent.
Does this sound correct to anyone else? All I need is a way to have a script execute on a slow loop outside of update. I guess I will have to rewrite my code to have update trigger the outside script on a condition instead.
if you run the below script in a empty level on the iphone and watch your heap ussage it will slowly rise.
function Start () {
timeCheck ();
}
function timeCheck () {
runTimeCheck ();
}
function runTimeCheck () {
yield WaitForSeconds (0.25);
timeCheck() ;
}
I’d imagine it works in a similar way as WaitForSeconds though. I’ll have to take a look at the memory issue here, but are you sure this is specific to the WaitForSeconds and not just regular engine rise and fall of memory usage? Is memory consumption just increasing, or does it eventually release?
the memory will garbage collect sooner or later but a GC causes a hitch so i am trying to remove things that could cause needless GC.
I have not tried InvokeRepeating yet, I will look at that later today.
This is not the standard rise and fall of memory. if you run a empty level this issue does not happen. it might be happening for multiple reasons but in my search to reduce GC i found the heap used goes up with a waitforseconds use but it doesnt if i rewrite the script to use a if(check time difference) method.
thanks for the idea of invokerepeating… I hope that works so my scripts are faster and easier to read.
yield waitforseconds actually creates an entry in the event queue and links in the current script task running there for reschedule. Coroutines are nothing else than asyncronous running script instances, if they are meant to wait or happen alter, they need to be rescheduled.