Instantiated object uses more RAM?

Hi folks,

I’m trying to optimize my game to reduce RAM usage on the iPad.

I’m loading and instantiating a model via Resources.Load (e.g. myObject = Instantiate(Resources.Load(myPrefab));). In testing the RAM usage on the iPad (with Instruments > Activity Monitor) I have found that loading the model in this way uses significantly more RAM than when I just put the prefab on the stage of the scene.

I thought it might be due to the fact that my model is static (and marked as such in the Inspector); the prefab was saved in the same static state but I thought maybe loading it dynamically removed it from static batching.

I added some code (StaticBatchingUtility.Combine(myObject)) in an effort to alleviate this problem but it didn’t seem to do anything.

Does anyone know why instantiating a prefab would use more RAM? Is there any way to avoid this? Am I not using the StaticBatchingUtility command correctly?

Thanks,
Jared

I could be wrong but batching is about rendering more efficiently. I wouldn’t expect it to have anything to do with memory. Loading a 1mb prefab would increase memory by 1mb, instancing it once would probably double it, the second instance would be better (and faster) I would expect. Note that i don’t know for sure what optimizations are going on under the hood, so this is just a simple example.

I would think the only way to use less memory would be to make your asset, or its references (textures, etc), smaller.

That was my understanding of batching as well, but I found that making the objects static in the Inspector did significantly improve my RAM usage on the iPad.

Really, I’m trying to understand why when I instantiate the object via the code I’m using more RAM than when I just include it on the scene from the get go.

Thanks,
Jared

From what i know, constantly instantiating seems to use more resources than just pooling them. But i think the instantiating have being improved in the 3.4 Unity. (I think it’s improved. From the improvement, it says faster executing). I think if there’s only a few objects, might want to try disabling and enabling them when you need it. Might be faster that way than instantiating. Hope that helps.