How do I swap two objects in a GC language without triggering GC?
- by TenFour04
I have two array lists. that I want to swap each frame. My question is, does the variable 'temp' need to be a member variable to avoid triggering GC, assuming this method is called on dozens of objects each frame? I'm not creating a new object, just a new reference to an object.
public void LateUpdate(){
ArrayList<int> temp = previousFrameCollisions;
previousFrameCollisions = currentFrameCollisions;
currentFrameCollisions = temp;
currentFrameCollisions.clear();
}
I've been told there's no reason to make a primitive into a member variable just to avoid GC, so my best guess is that this also applies to object references.