In the ongoing process of optimizing our game...
We found out that "Invoke" - the method to call a function in Scaleform - also generates garbage.
It create a Value object to hold the returned data from the function called... even if this function returns nothing.
Since often we do a one-way invoke like "Invoke("UpdateScore", newScore);", we do not care about the returned value. Also, in the case of an updated score, it can easily be called every frame. Garbage generated every frame is never a good thing.
So, we created this in the Value class;
private static Value returnCache = new Value(); public void InvokeOneWay(String methodName, params object[] objs) { int numElem = objs.Length; IntPtr ptr = Serialize(objs); #if UNITY_WP8 bool result = sf_invoke2(this, methodName, numElem, ptr, returnCache); #else bool result = SF_Invoke2(this, methodName, numElem, ptr, returnCache); #endif Marshal.FreeCoTaskMem(ptr); }
The return value is static and is never used. Using this reduced our Scaleform garbage generation to almost 0.