Default-Diffuse material leak - how to find source?

Hello,

I have this highly convoluted project. Now recently I noticed, that when running it, it slowly gobbles up memory until finally either Unity or the game crashes from lack of memory.

So I used the DetectLeaks script and found out that the game creates like.. a few thousand materials per second. All called "Default-Diffuse (Instance)". I can "find" and destroy them, nothing in the game seems to change, but the memory problem is fixed, except for the performance hit of finding and destroying them in the first place.

But of course I'd rather be interested in finding out, where they come from. So, does anyone have an idea how I could find the object/script responsible for creating them?

And no, turning more and more parts of the game off will not work, as it is very entangled and one thing doesn't work without the other (hooray..). Please share your brilliant insights!

First thing I would do is a project wide search for new Material(

After that it gets a little trickier, but you'll probably want to look for Instantiate, and see if any of them have materials as the object to instantiate

Not the most ideal methods I know, but I can't think of any easier ways

Well. Through try and error I found the cause of the problem to be an animation, that fades the color of the material of an object. It seemed like in some cases the material could actually not be found from the animation (modified the subobjects).

Instead of using an animation, I now fade the material with an Enumerator, which works good enough.

Lesson learned: if I could start this project over, I'd use a lot less animations for mundane tasks.