简体   繁体   中英

Libgdx ShapeRenderer lag

I have created a simple game for android using the LibGDX framework. Unfortunately the game sometimes begins to stutter for a brief moment, which ruins the experience. I figured this might be due to garbage collection so I had a look at the memory monitor:

The allocated memory constantly increases from like 10mb until it reaches the memory limit, where it just drops back down to 10mb. Looking at the Heap leading the list is FinalizerReference by a huge margin.

查看堆文件

I really cant't tell where this is coming from. I haven't written any Classes with finalize also I use the pooling function provided by LibGDX to keep the number of created objects down. You can actually see the most expensive of my Objects Spinner in the list, which sits at a constant 8. I have read through all other threads regarding similar issues, but I didn't found an actual solution.

I'm grateful for help of any kind! I can provide some more info if needed!

Edit

  • changed the title to fit the actual problem

So i solved the stuttering issue. Afer a good night's sleep I decided to have another look at my rendering and I turns out the ShapeRenderer I used quite a bit for rendering simple shapes caused the lag. I replaced all ShapeRenderer calls with SpriteBatch calls, writing own methods for drawing lines and circles and It now runns smoothly.

Heap dump still shows FinanziererReferences taking up a lot of memory and I space still grows although the app idles but the stuttering is gone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM