开发者

Set GC time limit / Remove allocation in Events

Is there a way to set a time limit on the GC?

I'm asking because I'm writing a game which allocates some floats, ints and longs on each event, and I'd rather call the GC for a short period of time (5-20ms) to remove those. I'd then call the GC in each Game Loop. This way would be my personal favourite as I still have some allocations which I can't backtrace without a lot of effort (I've already 开发者_高级运维removed most stuff).

Alternatively I'd look for the other allocations and prevent them somehow, but then I'd need a way to prevent allocations in events.

Here's the result of allocation tracker if needed: http://textsave.de/?p=67220

EDIT: I can't really find anything with the allocation tracker, all the objects are from some far off java-internal class (even in the trace). Also, the shown objects are nowhere near the numbers being collected (unless the garbage collector counts float[] as multiple objects).

Anybody have this problem?


Is there a way to set a time limit on the GC?

No, but it is already fairly short.

I'm asking because I'm writing a game which allocates some floats, ints and longs on each event

Don't do that. Pre-allocate your memory.

and I'd rather call the GC for a short period of time (5-20ms) to remove those. I'd then call the GC in each Game Loop

You are welcome to call System.gc(), but you cannot control the duration for which it runs. It is usually on the order of low tens of milliseconds. However, you are better served by avoiding the allocations in the first place, by maintaining your own object pool.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜