question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak in ModelBatch.render()

See original GitHub issue

While profiling my Android application I have noticed that every frame the number of allocated objects is increasing (see the white line on the screenshot below).

Issue details

Preliminary investigation has shown that every call of ModelBatch.render() creates an instance of ArrayList iterator.

Screenshot 2020-07-05 12-28-43 As I understand, while there is a forEach() call, Iterable<T> create the iterator on every call, every frame.

for (final RenderableProvider renderableProvider : renderableProviders)
     render(renderableProvider, environment);

I know there is a flag Collections.allocateIterators which could be a reason for that (by default it is “false”, which is good). Even when I have set it to “false” explicitly, it did not help.

Reproduction steps/code

My code which call the render is quite trivial:

modelBatch.begin(camera)
modelBatch.render(modelList1, environment) // modelList1 - ArrayList<ModelInstance>
modelBatch.render(modelList2, environment) // modelList2 - ArrayList<ModelInstance>
modelBatch.end()

Version of LibGDX and/or relevant dependencies

gdxVersion = ‘1.9.10’ roboVMVersion = ‘2.3.8’ box2DLightsVersion = ‘1.4’ ashleyVersion = ‘1.7.0’ aiVersion = ‘1.8.0’

KotlinVersion = “1.3.72” Java version = “1.8.0_251”

Stacktrace

iterator:806, ArrayList (java.util)
render:272, ModelBatch (com.badlogic.gdx.graphics.g3d)
render:76, MySceneRenderer (com.mysupergame.game.ui)
...

Please select the affected platforms

I have experienced that for Android platform, and did not check for others, assuming it is not related to the platform.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
obigucommented, Jul 5, 2020

The memory issue you describe is not a memory leak nor the problem is in the render() implementation. Use an Iterable implementation that doesn’t allocate by making modelList a com.badlogic.gdx.utils.Array instead of a java.uitil.ArrayList.

0reactions
JackRainycommented, Jul 5, 2020

@obigu , thank you for the advice using the com.badlogic.gdx.utils.Array instead of java.uitil.ArrayList. It has helped. Now I would say it is an imperfection of ArrayList implementation. Anyway, it is not related to render() method now. I close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug: Memory Leak when rendering arrays · Issue #20368
I created a React hook called useMemoryLeaksDebugger using the WeakRef API to find memory leaks. I found many real memory leaks on my...
Read more >
Memory leak caused loading textures, despite calling ...
The textures render absolutely fine, but the loading causes memory leaks. The application memory size keeps increasing when I check it on task...
Read more >
Re: Memory Leak in MFR during Render - 12592344
So I end up babysitting a render and restart it from the failed frames every 8,000 frames or so. I think there is...
Read more >
Memory management - libGDX
Failure to dispose resources will lead to severe memory leaks! ... Model; ModelBatch; ParticleEffect; Pixmap; PixmapPacker; Shader; ShaderProgram; Shape ...
Read more >
3DS Max 2021 Arnold CPU Rendering memory leaks
I guess the memory leaks are caused by each render() commands (probably an Arnold renderer issue). Any idea on how to fix this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found