Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by DDeathlonger · May 24, 2018 at 05:26 AM · coroutineswhile-loopgarbage-collection

Why is my Coroutine Continuing to allocate GC from the "MoveNext()" After it completes?

I try to be straightforward in my titles... it's exactly what it sounds like.

I simply call a single Coroutine, which does not call any other coroutines, at any time... I call this single coroutine via the "StartCoroutine(Coroutine())" method at the Start() method.. (this also occurs when I call it from Awake or anywhere really.)

Shouldn't it only be getting called once???

Nevertheless, I am getting MAJOR Lag Spikes from GC Alloc according to the profiler, from this coroutine being repeatedly called... this issue persists in numerous scripts I've written. I'm completely confused rn; I'm about ready to never use Coroutines again...

https://pasteboard.co/HmBHlzE.png (The Image Previewer is not working... lol)

Also, I am NOT calling it from ANYWHERE else, even though it says it's getting called from the Update method, I have triple and quadruple checked with our 'ol friend Ctrl+F... it's ONLY in Start().

Any input is appreciated.


UPDATE:

So I've FINALLY found out what is causing it to continue calling the Coroutine.. though it doesn't make sense.. here's my test:

Code (CSharp):

         private IEnumerator Test()
         {
             while (brainStarted != BrainStarted.True)
             {
                 debugLog = "WAITNG....";
                 yield return null;
             }
  
             debugLog += " - EXITED";
         }



and of course it DOES meet the exit condition after a short time... and surely enough, I DO get the " - EXITED" logged. (debuglog is just a reference to a static UI text Component) although the conditions are met, it continues to call the Coroutine.... I'm continuing investigation - still input is welcome from anyone. The issue is pertaining to while loops inside of Coroutines... this is very strange.


UPDATE:

So only a minor update, but I also noticed this:

https://pasteboard.co/HmBViNr.png

And again, this coroutine (Test()) is merely called one time in the Monobehaviour.Start() method. Via StartCoroutine(Test());

I changed the exit condition from my enum to a bool to verify the issue is not related to the enum... the issue persists.


UPDATE:

Here's an isolated Class I've built for proper testing (still occurring):

Code (CSharp):

 using BrainConnect;
 using System.Collections;
 using UnityEngine;
  
 public class Test : MonoBehaviour {
  
     private bool brainReady = false;
  
     void Start ()
     {
         ConnectBrain.BrainReady += BrainReadyEvent;
         StartCoroutine(TestEnumerator());
     }
  
     private void BrainReadyEvent(object s, System.EventArgs e)
     {
         brainReady = true;
     }
  
     private IEnumerator TestEnumerator()
     {
         while (!brainReady)
         {
             ConnectBrain.debugLog = "WATING....";
             yield return null;
         }
  
         ConnectBrain.debugLog += " - EXITED";
     }
 }
  

This new isolated script is simply attached to a new Empty GameObject Parented under nothing. I get the same results.

https://pasteboard.co/HmC1eu3.png

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whatever560 · Jul 24, 2018 at 10:42 AM 0
Share

I'm having a similar issue with 10$$anonymous$$B of GC allocated a some specific times on Coroutine.$$anonymous$$oveNext

[Edit] : Do you have any update on this ?

avatar image Bunny83 Whatever560 · Jul 24, 2018 at 01:59 PM 0
Share

No, just no. You can't have the exact same issue as you do not have the exact same code. We don't even know all of his code so it's impossible to know.


If you have a question, please Ask a Question and do not post an answer to another question that doesn't answer the question at all. Also if you want any progress with your specific issue you have to include much more details in your question. Show the exact code you're using and as i said in my answer here, include a deep profile.

avatar image Whatever560 Bunny83 · Jul 24, 2018 at 02:26 PM 0
Share

@Bunny83 Chill down please. First I was not talking to you. 2nd I'm having exactly the same issue and symptoms as @DDeathlonger with a similar code, beeing : "How the hell do you debug those GC.Alloc from Coroutine.$$anonymous$$oveNext()" and I wanted to know if he had any follow up.

The only thing I can agree of is I should have written a comment though I'm always trying to juggle with the absolutely not straightforward 4 support channels forums+answers+qa+bug reports of unity.

I should have taken more time to answer this, but you're no one to judge. Finally the interesting part of your answer is "include a deep profile". Which is the only thing I was asking for. Hope it'll help though.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jul 24, 2018 at 01:55 PM

Sorry but your profiler results clearly do not belong to the code you've shown. In your image of your first update you clearly use something like ReadPixels inside that offending coroutine and this call is causing the memory allocation, not the coroutine itself.


Next is we don't really see which frame of the profiler we're currently looking at.


The next suspicious thing is that the profiler shows the MoveNext call inside the Behaviour Update of your script. Coroutines are usually continued from the "Update.ScriptRunDelayedDynamicFrameRate". There you'll find the "CoroutinesDelayedCalls" where the actual coroutine would be continued.


To me that looks like you somehow manually try to call MoveNext on an instance of your IEnumerator. However your code clearly doesn't match your results.


Your last image also shows the MoveNext call from inside of the Update call of your ConnectBrain class.


You haven't mentioned which Unity version you're using. The exact point from where the coroutine may be continued automatically may have changed. My observations has been done on Unity 2018.1.3f1 (I just saw that you used 2017.3.1f1 on your screen shot)


Anyways your code doesn't look like it's matching your profiler results. You may want to turn on deep profile at the top of the profiler to basically get a complete stack trace inside the profiler.


If you need still help with this you have to include more details, a deep profile picture and maybe the exact code you're using inside a new empty project without any other code interfering.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Whatever560 · Jul 25, 2018 at 10:09 AM 0
Share

This helped to get the source of the issue :

You may want to turn on deep profile at the top of the profiler to basically get a complete stack trace inside the profiler.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

84 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Coroutine stops after while-loop 1 Answer

When there is a while-loop in a Coroutine, if I have a "yield" within the while-loop, does that mean the Coroutine will be re-entered within the while loop? 1 Answer

While loop out of control...maybe? I'm not sure. Trying to track Coroutines progress. 1 Answer

Can't figure out While Loop crash? 1 Answer

Time.time undependable in a coroutine? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges