Android Service for capture framebuffer - android

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.

Related

Xamarin Android profiler memory dump?

For the few days, I've been trying to find out why my app allocates massive amounts of memory and crashes. I'll open a few layouts that admittedly is not optimized. But I cant figure out why sometimes StartActivity() will allocate up to 80MB at a time, and why that memory wont release when I close the activity.
I created a test application filled with images and two layouts that call each other. Using Xamarin Profiler, I came across this memory dump, and I cant figure out what is calling this and how can I have it called more often for my real app?
Please, any insights would be lovely.
I cant figure out what is calling this and how can I have it called more often for my real app?
The Memory Profiler in Android Studio can help you to see how your app allocates memory over over time. It could also be used for xamarin android app.
And try to use IComponentCallbacks2 interface and implement Application.OnTrimMemory to incrementally release memory based on current system constraints.
You could refer to Manage your app's memory for more information.

LibGDX game freezes (because of a mulithreading issue?)

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)

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.

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.

Detect causes of performance problems?

I have an android app that is getting fairly large and complex now, and it seems to have intermittent performance problems. One time I will run the app and it's fine, another time it will struggle when switching views.
How can I detect the causes of the performance problem using debugging tools so that I may correct it?
Use the ddms tool which comes with the SDK. It has a nice feature called Allocation Tracker that allows you to see in real time how much memory your code is consuming and what specific line is causing that.
Most of the cases your app will slow down because of bad adapter implementations, poor layout inflation techniques or not using a cache system to decode Bitmaps (such as using SoftReference).
Take a look at this article for a brief explanation: Tracking Memory Allocations
In addition to the tool Cristian mentioned, Traceview is another helpful one. It's not very well documented but it can give you information about how often methods are being called, and which methods are taking a lot of time.
Another good memory tracking tool is MAT, here is a page that describes how to use it with Android: http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html
Both the tracing and the heap dumps can be done through the DDMS panel, if you prefer not to work with the command line. In Eclipse, in the devices panel, under the device/emulator you are using, click on your app (listed by package name), and you can then Start/Stop Method Profiling to get a trace and you can use Dump HPROF to get a heap dump. Note, the dumps need to be converted to work with the MAT plugin. The attacking-memory-problems-on-android above describes how to do that.

Categories

Resources