Problem: CACHE_STRATEGY is too agressive

When building flexible UI in Unity3D you may sometimes see this message on the Unity console:

FlexBuilder: Your CACHE_STRATEGY is too aggressive! - Cache contained an object Unity had already destroyed

TL;DR: quickest solution

If you just want to make the warning go away then you can safely comment-out the line of code that produces it.

Double-click on the warning in the Unity Console, it will automatically open your script editor, and you can put "//" at the front of the line to comment it out:

Longer answer: what does it mean?

Flexbuilder is much faster at doing layout than core Unity (and in a lot of cases: faster even than Unity's UIToolkit even though that is supposedly implemented partly in native code, and should be fast). Part of that speed comes from its intelligent internal caching systems. There are multiple caches (the exact set of caches depends on which version of FlexBuilder you're running - the free/Lite version has only one cache, the Standard version has 4 or 5 caches, and the Pro version has a much more complex, super-fast, meta-cache).

This warning message comes from the main default cache (as of 2023 this is included in the Standard edition on the AssetStore). It's trying to intelligently cache and re-use information that hasn't changed for the last few frames - but it cannot see the future, so in a few cases it guesses at what can still be cached - and sometimes Unity deletes objects this frame before the cache has a chance to discard them.

A future version of FlexBuilder may remove this warning - it's possible to track every object more precisely, but it costs some performance.

FlexBuilder Pro users

If you're running FlexBuilder Pro and you see this message, please contact support -- the meta-cache in FlexBuilder Pro shouldn't ever trigger this message, and if it does it means it's falling-back to the Standard caching (and your performance is lower than it should be).