Reference handler thread lag issues

So I’m working on a game with an open world esq environment and it currently is a bit of a memory whore which I’m working on however after running a memory check on the code I find that the memory is pretty well contained other than the graphics methods and yet I still get lag spikes, after investigating I found that the reference handler thread would spike up every now and again and seems to be the cause of the lag.

What causes this thread to actually spike up , I understand it’s to do with the garbage collector so would reducing my use of throwaway objects for arguments (eg some_function(new Vertex(x,y))) help with this problem?

Hmm I found the problem , turns out my legacy code was creating 6 unnecessary float buffers all of monstrous size in a rather high traffic section of code which was basically bottle necking the entire code.

[quote]public class Entity {
private final Vec2 position = new Vec2(), rotation = new Vec2();

public Vec2 getPosition() { return position; }
public Vec2 getRotation() { return rotation; }
}
[/quote]
I am not sure why you would make a lot of

[quote]my use of throwaway objects for arguments (eg some_function(new Vertex(x,y)))
[/quote]
You could just call some_function(entity1, x, y) and get away with it easier imo.

You should shy away from using throw-away objects in render methods, and recursive functions. Otherwise, to notify an object needs to be cleaned you can just set it to null, and if the old value isn’t referenced anywhere else theoretically it’s clean.