How do I swap two objects in a GC language without triggering GC?

Posted by TenFour04 on Game Development See other posts from Game Development or by TenFour04
Published on 2012-10-26T16:08:55Z Indexed on 2012/10/26 17:21 UTC
Read the original article Hit count: 163

Filed under:
|
|

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.

© Game Development or respective owner

Related posts about c#

Related posts about optimization