I was wondering what I thought yesterday.
I apologize in advance for the misleading headline, but I really don't know how to do this. Well, suppose we are two objects ObjA
and ObjB
, and that, for example, ObjB
has a method that takes an ObjA
object as an argument.
We can do this (taking java as a language):
ObjA instanceA = new ObjA(); ObjB instanceB = new ObjB(); instanceB.method(instanceA);
or
new ObjB().method(new ObjA());
Suppose that this is the body of some function, so the objects will be destroyed when leaving the scope. My question is:
do we get a performance advantage by not instantiating special objects and implicitly referring to the second code?
Is it worth the readability?
Or is all this in vain, since implicitly created objects will be stored in memory and in any case die by region?
Note. I don’t know if I say “implicit” or “anonymous” correctly, but I haven’t found much on Google.
source share