Creating Library - Worried about garbage collection

Hi and happy new year!,

I have decided to create my own go to library of common functions that I have written and would like to reuse in an easy to use package in my projects. Sudo code example:

using UnityEngine;
using System.Collections;

public class mathSolutions : MonoBehaviour {
	
	public class mathSolutions : MonoBehaviour {
		
		public static Vector2 someVector2Function(Transform object1, Transform object2)
		{
			
			Vector3 variable1;
			Vector3 variable2;
			float variable3;
			
			// Other sudo code
			
			return new Vector2(result1, result2);
		}
		
		
		public static Vector3 someVector2Function(Transform object3, Transform object4)
		{
			
			Vector3 variable4;
			Vector3 variable5;
			float variable6;
			
			// Other sudo code
			
			return new Vector3(result1, result2, result3);
		}
	}
}

So for example I could import the above script into Unity, and access the functions like this:

mathSolutions.someVector2Function(player, target);

However, I am worried about garbage collection as I am declaring my variables in the functions. Am I right in thinking that this method will increase garbage collection? Any suggestions on best practice for this?

I have read that it might be best to store each of my own functions in their own script and compile them to a DLL, that way I can pre-declare the variables at the start of the script, and avoid having the library script getting massive over time. Would this be the better option?

Thanks!

Generally speaking static method variables are on the stack per call. They are out of scope by the time you end or exit the method, when you pass reference types in, thats all they are, a pointer to something, if you instantiate a new object that goes out of scope, that will be placed in Gen0 for collection.

Read some about GC here