SpriteBatch memory leak?

Anything libgdx related goes here!

SpriteBatch memory leak?

Postby vsirvent » Sun Mar 30, 2014 6:37 pm

Hello,

We're developing a game using version 1.0.0 from repository and we're facing memory leaks (in native memory, not java heap) while switching from one screen to another. We have taken care to call dispose() method whenever needed, but we're not able to solve the memory leaks.

I've made a simple test code:

while (true) {
SpriteBatch batch = new SpriteBatch();
batch.dispose();
batch = null;
System.gc();
}

And at the moment my program native memory is continously growing (at the moment 1GByte). Can it be a bug in the JNI implementation of the SpriteBatch? or is there any other way to sove this memory problem?

I've run Valgring but it gives lots of false errors when running java, any idea about how to detect the memory leak in the java native code?

Thanks in advance,

Vicente Sirvent
vsirvent
 
Posts: 13
Joined: Sun Mar 30, 2014 6:27 pm

Re: SpriteBatch memory leak?

Postby evilentity » Sun Mar 30, 2014 10:10 pm

How are you measuring this?
Looking for a freelancer? PM me!
Check out libgdx discord server!
evilentity
 
Posts: 4867
Joined: Wed Aug 24, 2011 11:37 am

Re: SpriteBatch memory leak?

Postby nems808 » Sun Mar 30, 2014 10:27 pm

You shouldn't be creating new SpriteBatch continuously, that is, it shouldn't be created inside of any while loop (i.e. render method). In your screen class call it only in your show or create method.
nems808
 
Posts: 48
Joined: Thu Sep 12, 2013 9:36 am

Re: SpriteBatch memory leak?

Postby Magnesus » Mon Mar 31, 2014 7:01 am

nems808 wrote:You shouldn't be creating new SpriteBatch continuously, that is, it shouldn't be created inside of any while loop (i.e. render method). In your screen class call it only in your show or create method.


It's only a test code, you know. To show the issue.
Magnesus
 
Posts: 1709
Joined: Sun Sep 25, 2011 3:50 pm

Re: SpriteBatch memory leak?

Postby Semtiko » Mon Mar 31, 2014 7:15 am

Use Java VisualVM (included in JDK).
Semtiko
 
Posts: 736
Joined: Tue Oct 18, 2011 9:03 am

Re: SpriteBatch memory leak?

Postby imagnity » Mon Mar 31, 2014 9:11 am

I am not sure where it is coming from. But I have been profiling my game recently using VisualVM and noticed that even when the game is paused, memory still grows like ~1MB in every 10 seconds or so. I am still not able to find out which object it is coming from as I don't see any object is being created or cross referenced from my game. I see float buffer is allocating a lot though.
Check out my games - http://www.imagnity.com/games/
imagnity
 
Posts: 197
Joined: Mon Mar 25, 2013 6:27 pm

Re: SpriteBatch memory leak?

Postby Semtiko » Mon Mar 31, 2014 9:36 am

imagnity, you are not alone. I try to figure out same "issue" couple weeks. Of course not all day long )) Generally my project works fine, but on ios it cause stuttering every ~10 second (drop fps on 10-20% down. hello GC), because robovm backend have a lot of crap in the "head" yet.
Semtiko
 
Posts: 736
Joined: Tue Oct 18, 2011 9:03 am

Re: SpriteBatch memory leak?

Postby vsirvent » Mon Mar 31, 2014 9:59 am

Hello,

I'll try VisualVM tool. Can it be used to check the JVM native memory usage or just the application heap memory?

Any idea about the memory leak?
vsirvent
 
Posts: 13
Joined: Sun Mar 30, 2014 6:27 pm

Re: SpriteBatch memory leak?

Postby vsirvent » Mon Mar 31, 2014 10:01 am

evilentity wrote:How are you measuring this?


You can check it with task manager in windows or with "top" command on Linux/Android
vsirvent
 
Posts: 13
Joined: Sun Mar 30, 2014 6:27 pm

Re: SpriteBatch memory leak?

Postby imagnity » Mon Mar 31, 2014 11:47 am

Semtiko wrote:imagnity, you are not alone. I try to figure out same "issue" couple weeks. Of course not all day long )) Generally my project works fine, but on ios it cause stuttering every ~10 second (drop fps on 10-20% down. hello GC), because robovm backend have a lot of crap in the "head" yet.


Semtiko - If memory continuously grows as I stated, eventually GC would kick in, then the stuttering makes sense. But why would the memory grows this much during pause state as only a few things are taking place-

1. Clear screen
2. Draw pause menu which has no allocation as they were created during load
3. Listen to the touch event

When I go home, I will check SuperJumper on VisualVM..if it's the same with this demo on Pause state.
Check out my games - http://www.imagnity.com/games/
imagnity
 
Posts: 197
Joined: Mon Mar 25, 2013 6:27 pm

Next

Return to Libgdx

Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 1 guest