Android:java.lang.OutOfMemoryError:线程创建失败

发布于 2024-11-24 02:21:26 字数 714 浏览 0 评论 0原文

我最近在 android 市场上上传了我的应用程序,但收到以下错误,我无法追踪它:

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)

我知道这是内存不足错误,但 stacktrace 没有提供它在我的代码中启动的任何信息。因此,我正在努力追踪它,因为我有一个相对较大的应用程序(20 个活动),其中包含大量异步任务和线程。不知道从哪里开始。任何帮助都会有益的

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一影成城 2024-12-01 02:21:26

您需要重新设计您的应用程序。在任何情况下您都不应该有 20 个活动。添加大量异步任务和线程只会使问题变得更糟。考虑将一些活动或异步任务压缩在一起,以使用更少的内存。不幸的是,没有任何神奇的方法可以调用来解决这个问题。您可以使用 DDMS 中的线程分析来查看哪些线程使用最多的内存;这应该可以帮助您找到从哪里开始。为此,请插入您的设备/启动模拟器。在 Eclipse 中,转到 DDMS 并在左侧面板中选择应用程序的包名称。单击“更新线程”按钮,您的应用程序正在使用的所有线程将显示在右侧面板上。您可以单击其中一个并点击“刷新”以获取有关它的更多信息。要查看内存的去向,请单击应用程序的包,然后点击“更新堆”(看起来像一个绿色的小垃圾桶)。转到右侧面板上的“堆”,然后点击“Cause GC”。这将向您显示应用程序内存中的所有内容。这至少应该可以帮助您入门。

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.

水溶 2024-12-01 02:21:26

您可以使用此代码片段登录 AsynTasks 以及活动 -

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

获取显示内存信息,以便了解问题开始出现的位置。

另外,请考虑在 onLowMemory 中放置一个断点,并确保它冻结虚拟机而不是线程,并检查线程以查看哪些线程导致了问题。

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.

飘逸的'云 2024-12-01 02:21:26

自己捕获崩溃并记录应用程序的总线程数。检查是否有漏线现象。

catch the crash by yourself and log the total threads of the app. Find out whether there is a thread leakage.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文