Unity is working on something, but on what?

Hello guys!

I am working with the Editor script and have a quite complex structure, containing different gameObjects.
Before I start some tasks through a separate thread, before that - I am storing different Scripts on those gameObjects into a single list.
I call this process “ScriptBaking”.
That includes using GetComponent for many of those objects at once 200+. It’s unavoidable, since I need to store a reference to those script instances, but it’s not the problem.

Keep in mind that all of this is happening in the Editor script.
I display a progress bar as I am working through the bake process.

This bake process is of course not threaded. It goes well, and takes about 4 seconds to go through all the game objects, I get a nice reference to the scripts. It’s okay if I do it again and again, until somewhere at 4th bake - the progress bar starts to really turtle somewhere from 70%. 5th time it will turtle at 60% and so on.

Moreover, I can see that unity is still doing something in the Mac menu. Please have a look at the picture. The progress circle makes a full turn, then starts again?

after some time (4-5 minutes after 5 re-bakes) the progress circle, or pie on the thumbnail hides after several laps. “Bake” is fine once again.

WTF is happening? :smiley: Is it an automatic clean-up some sort? How is the progress circle tied with the turtling of “Baking”?

here is the function, gets invoked on button click from OnInspectorGUI( )

//the variables declared and initialized on the top of the editor script

NodeCounter _nodeCounterShort = GameObject.Find("mainNodeCounter").GetComponent<NodeCounter>();
//Node Counter contains the list of all gameObjects in the scene, "the nodes.

void BakeNS(){
		float counter = 1; //used to display progress

		foreach(GameObject g in _nodeCounterShort._AllNodesInScene){
			NodeSpark _dump = g.GetComponent<NodeSpark>();
			_dump._NSneighbour.Clear(  );
			foreach(GameObject gg in _dump.neighbours){
			EditorUtility.DisplayProgressBar("saving the NodeSparks of neighbours for every node", counter + "/" + _nodeCounterShort._AllNodesInScene.Count, counter/_nodeCounterShort._AllNodesInScene.Count);
	}//end of BakeNS()

Does anything in your Process create a lot of objects and throw them away again?
It could be that after a few starts, you get memory pressure and the Garbage Collector kicks in.

Can you check your memory consumption while running your Baking?

Also, does it help if you call the Garbage Collector yourself after every run?

GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);

But keep in mind that the above may not be the best idea to put in production code - it’s just to test if that’s the problem. If it is, you would be well advised to try to improve the memory consumption issue.