First let me provide context:
In C# an object passed into a method is passed via reference. The reference is only lost if the passed in object is re-instantiated with the keyword new
So, I like to do things like var obj = Alter(obj)(method 1) i.e. I pass in an object and return the object. As opposed to doing the equivalent: Alter(obj) (method 2) where the referenced object is changed the same, except by reference instead of returning a copy. I would argue the first one is better since if some daredevil coder later modifies the code to use a keyword “new”… existing code won’t burn and die.
My question is will method 1 use significantly more memory than method 2 or will it cause any other performance degradation? i.e. will this invoke the GC more often?
The answer is NO
C# never copies a reference type. If you pass in obj to your method and then return it, that is the same exact object instance you started with.
That does not create additional pressure for the GC.