Android: java.lang.OutOfMemoryError: thread creation failed

I recently uploaded my application to the Android market and I am getting the following error which I cannot track:

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 that this is a memory error, but stacktrace does not provide any information on where it is running in my code. Therefore, I try to keep track of this, as I have a relatively large application (20 activities) with lots of AsyncTasks and threads. I don’t know where to start. Any help would be helpful

+4
source share
2 answers

You need to redesign your application. Under no circumstances should you have 20 activities. Adding a large number of AsyncTasks and Threads only exacerbates the problem. Consider condensing some of your actions or AsyncTasks together to use less memory. Unfortunately, there is no magic method to call to fix this. You can use thread profiling in DDMS to see which threads use the most memory; this will help you find where to start. To do this, connect the device / start your emulator. In Eclipse, go to DDMS and select the name of your application in the left pane. Click the "Update Threads" button, and all the topics that your application uses will appear in the right panel. You can click on one and click "Update" to get more information about it. To find out where your memory goes, click on your application package and click on "Update Heap" (looks like a little green garbage). Go to "Pile" in the right pane and click on "Cause GC". This will show you everything that your application has in mind. This should at least help you get started.

+4
source

You can enter AsynTasks, as well as actions along with this fragment -

 MemoryInfo mi = new MemoryInfo(); ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); activityManager.getMemoryInfo(mi); long availMem = mi.availMem ; 

to get information about the displayed memory, to get an idea of ​​where the problem starts to appear.

Also, consider putting a breakpoint in onLowMemory and make sure that it is VM dependent, not thread specific, and checking threads to see which ones are causing the problem.

0
source

All Articles