Reputation: 135
I recently uploaded my app on the android market and I am getting the following error that I cant trace it back:
java.lang.OutOfMemoryError: thread creation failed
at java.lang.VMThread.create(Native Method)
at java.lang.Thread.start(Thread.java:1327)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:901)
at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:950)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1086)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
I understand it is out of memory error but stacktrace doesn't provided any information where it is started in my code. So I am struggling to track it down as I have a relatively big application (20 Activities) with alot of AsyncTasks and threads. Don't know where to start. Any help would be beneficial
Upvotes: 5
Views: 6008
Reputation: 1211
catch the crash by yourself and log the total threads of the app. Find out whether there is a thread leakage.
Upvotes: 0
Reputation: 4262
You can logging in AsynTasks as well as in activities along with this snippet -
MemoryInfo mi = new MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availMem = mi.availMem ;
to get display memory info in order to get an idea of where the problem starts to appear.
Also, consider putting a breaking-point in onLowMemory and make sure it freezes the VM rather than the thread and inspect the threads to see which ones are causing the issue.
Upvotes: 0
Reputation: 1754
You need to redesign your app. You shouldn't have 20 Activities under any circumstances. Adding lots of AsyncTasks and Threads only worsens the problem. Consider condensing some of your Activities or AsyncTasks together in order to use less memory. There's no magic method to call to fix this, unfortunately. You can use Thread Profiling in DDMS in order to see which threads are using the most memory; that should help you find where to start. To do so, plug in your device/start your emulator. In Eclipse, go to DDMS and choose your app's package name in the left panel. Click on the button that says "Update Threads" and all the threads your app is using will appear on the right panel. You can click on one and hit Refresh to get more info on it. To see where your memory is going, click on your app's package and hit "Update Heap" (looks like a little green garbage can.) Go to Heap on the right hand panel and hit Cause GC. This will show you all the things your app has in memory. That should at least help you get started.
Upvotes: 5