LibGDX game freezes (because of a mulithreading issue?) - android

After playing my libgdx-game for some time, it just freezes. the game loop is not being executed anymore and it does not react to any input; the game can just be killed.
Logcat says this:
The memory graph shows:
(The freeze starts at about 8m30s. Before this time the game is running normally.)
The question: What is happing here? What do I have to do to avoid this game crash?

Could you post more logcat? It's hard do gather any information as to what is causing the problem just by looking at it saying it's suspending all threads.
This usually happens when you run out of memory. Do you have peices of code which load stuff into memory? You may want to take a look at that. Just a possibility, but maybe you are running out of memory. I know what the memory graph shows, but I had a similar problem and I fixed it by optimizing some asset loading.
(you may want to use asset manager to handle memory optimization)
https://github.com/libgdx/libgdx/wiki/Managing-your-assets
If that is not the case, please post some code. (or more logcat)

Related

How to detect and solve android application performance issues?

I'm trying to figure why is my app stutter when a user is switching between activities and when a Dialog is created.
I dump my app performance in order to detect anomalies using Profiler and playing with the app for some time.
The only abnormality I managed to detect is the relatively huge number of "Native Size" of Bitmap, in comparison to to other objects:
But I don't really know if its abnormal and if so, how to investigate and solve it.
The app is pretty big so I think it would be best the share the whole repo for you to be able to view the code:
https://github.com/steingolditay/ezBalans
Open the activity which you think is lagging and in the logcat filter byword Choreographer, if you find
Skipped 60 frames!
in the logcat, it means that the application may be doing too much work on its main thread.
then you can optimize your calls and processing for that activity
I noticed in your memory screenshot there are four leaks detected by the memory profiler. Did you try clicking on the label to see what they are?
For debugging missed frames, use the CPU profiler to record a System Trace. See https://developer.android.com/studio/profile/cpu-profiler#frame-render. Once you locate red frames (longer than the 60 Hz threshold), look at your render/UI thread for long running trace events that might have contributed to the bottleneck. This video may be of help.

Android app taking too much memory for nothing

I have an app that is doing a lot of work related to Bluetooth connection and displaying graphs etc.
App is using many libraries as well. App has also a background service running all the time. Now I noticed that it is taking upto 500 Mbs of Memory Usage.
What I have done was commented out. Everything on app launch and just showed splash screen (custom made) and still footprints are 60-70 Mbs. That means something is taking too much memory without even using it.
One important thing is that Android Studio's Memory Monitor is showing me that app is using only 40-50 Mbs whereas my phone's Memory manager is showing upto 500 MBs. I have tested this on 3 phones. Result remains same.
Any help should be appreciable.
You are leaking alot of memory you can go to memory monitor in android studio and use garbage collector to have an estimation of the total amount of leak you're having.
Most of the time External libraries are main Issue for the memory leakage due to their differing implementations and are quite inefficient when used for work on mobile client.
Here is a great blog regarding memory leakage.
http://blog.nimbledroid.com/2016/05/23/memory-leaks.html
Use MAT Tool to find out memory leakage and resolve that.
Once started service, if it is no needed then stop the service using intent.
And also check you have started any timer thread and not stopped it.

How to modify my app/game so that it can load quickly?

I have created a simple game using a class a which extends SurfaceView and implements Runnable. In the game the drawing is done inside the public void run. Which is targeted by a thread as soon as the activity launches. The game is taking a lot of time(sometimes 10-15 sec) to load. As well as when the game is paused(thread. join()) and resumed(thread = new Thread(this); thread.start()) it takes too much time.
What might be making the game load slow? And what can be the solutions?
The most common cause is resource loading.
I/O operations are very slow, so, if you try and load all your bitmaps before actually drawing, this can cause significant delay before the drawing actually starts.
One strategy to avoid this is to preload your assets before you actually need to start using them. A lot of games do this in the so - called Splash screen. Also, don't be too fast to recycle your assets and free the memory they are using. This means that you will need to reload them the next time you start.
Overall, there is no exact recipe of how to do it - there is a constant trade - off between load times and memory consumption. You just need to experiment and try to see what fits your use case best.
Be sure to profile your app, examine the object creations and memory allocation calls using your IDE. Most of the time you can easily pinpoint the causes of problems there.
I found that the game was loading slow because the thread has been running continuously, without any sleep. So just adding Thread.sleep(15); inside the run, with all exceptions handled, solved this problem. Thank you for supporting.

android: How to manage memory between application starts (application failure on second run)?

Noob question!
My whiteboard/drawing app runs fine, using a combination of simple image views and bitmaps with me rendering a path to a bitmap and copying over as needed. I have it multitasking on my ICS Transformer without problems. However, if I exit the app with the Back button and then run it again, it fails; I get a memory error on the second run when I try to draw something.
Out of memory on a 4096016-byte allocation
Although sometimes I don't get that and it runs a second consecutive time. When I run it a third time, it works, and the fourth, again it Out-of-memory's.
What manual cleanup do I have to do when an Android app exits? Should I remove all created objects and bitmaps and paths and listeners and stuff?
Looks like you have a memory leak. Make sure you follow recommendations provided here. Often Memory Analyzer Tool is very useful in such cases. Here is a video how to use it.

Android Service for capture framebuffer

I am using a native code to capture the framebuffer using the link below
http://www.pocketmagic.net/?p=1473.
But my problem is that I want continous capture. Hence I am using service in Android so that it runs in background.
But my problem is that it gives low memory and dies after some time.
Then I tried with single activity and tried to capture the sam window many a times.
This time there is no problem even after 1000 counts.
The problem arises when there is service used.
Please help.
It is hard to say without seeing your source code - you should always try to include the smallest possible application that exhibits the problem behaviour.
At a guess I would say that you have memory hungry resources that are not being cleaned up and this is happening because your memory allocation and release code is not perfectly aligned with the life-cycle of the service. You could confirm this in a couple of ways:
Log the explicit allocation and release of memory and make sure your service is actually executing those parts of the code.
Use a memory profiler to find allocations that are not being released. This might be more challenging with native code than it would be in Java.

Categories

Resources