what is the garbage collection size of a script.

Hi,

When i make a projectile GameObject for example I usually make a “hollow” script that has the other projectile behavior scripts linked to it as varables, this way i just have to make a getComponent and i can access all the other scripts through it.

Now my question is: will all the linked scripts be counted when the GC comes into play ?
What is the memory size mechanics ?

Thx,

Paradoks

Your “hollow” script is allocating memory for each script you reference - each script adds one pointer (so 32 or 64 bits, depending on computer architecture). Then there will be some additional memory allocation for the MonoBehaviour functionality of your “hollow” script - things like the gameObject and transform property. Each of those properties is another pointer and there is likely a few additional private memory allocations happening within MonoBehaviour. So, assuming your script has reference to 5 other scripts, you’re looking at something in the ballpark of 30-60 bytes per “hollow” script (this is a very rough estimate), depending on the platform/architecture.

After a projectile is destroyed, the GC will eventually have to collect the projectiles memory and this hollow script is adding a bit more work.

I HIGHLY doubt that your application will be affected by this “hollow” script. If you suspect this is truly an issue then use Unity’s profiler and see where the problem really lies. It is almost guaranteed that other parts of your application will have far greater memory concerns than having an additional script on your objects. If you are creating hundreds/thousands of projectiles constantly and they each have this script then it could become substantial - but in that case what you should do is implement object pooling to reuse previously fired projectiles rather than instantiating new ones. If the objects aren’t instantiated and destroyed constantly there will be little to no pressure on the GC.