为什么我的 Android 应用程序会在手机上持续崩溃,但在模拟器上却不会崩溃

发布于 2024-09-16 19:09:58 字数 509 浏览 7 评论 0原文

我有一个应用程序,其中使用了很多图形。

当我在模拟器(1.5 - 2.2)上反复打开和关闭应用程序时,它运行良好,通过检查堆,我可以看到所有内容都已正确清理和GC。

但是,当我在 HTC Aria 手机 (2.1) 上运行我的应用程序时,每次我尝试重新打开它时,应用程序都会崩溃。当我查看堆时,我可以看到对象没有像在模拟器中那样被清理。

有谁知道为什么会发生这种行为?我确实在另一台 HTC Aria(朋友)上尝试过,它的崩溃方式与我的手机上相同,所以我认为它不仅仅是与我的特定手机隔离的。

任何关于为什么模拟器上的东西都能正常清理但在我的手机上却不能正常清理的想法或想法将不胜感激。需要注意的一件事是,几天前我确实让它在我的手机上工作并且运行良好,我没有做太多改变,现在它在我的手机上不起作用,所以这对我来说有点神秘。

谢谢!

注:
崩溃是由 OutOfMemory 异常引起的。我正在预加载一些图形,但没有足够的内存来同时运行应用程序的两个实例,因此它崩溃了,因为应用程序的第一个实例未正确清理。

I have an app that uses quite a few graphics in it.

When I open and close my app repeatedly on my emulator (1.5 - 2.2) it runs fine and by checking the heap I can see everything is being cleaned and gc'd properly.

However, when I run my app on an HTC Aria phone (2.1) the app crashes every time I try to re-open it. When I look at the heap I can see that objects are NOT being cleaned up like they are in the emulator.

Does anyone know why this behavior could be happening? I did try it on another HTC Aria (a friends) and it crashed the same way as on my phone so I think it's not just isolated to my particular phone.

Any thoughts or ideas would be really appreciated on why things are cleaning up properly on the emulator, but not on my phone. One thing to note, is that I DID have it working and gc'ing fine on my phone a few days ago and I didn't change much and now it's not working on my phone so it's a bit of a mystery to me.

Thanks!

Note:
The crash is caused by an OutOfMemory Exception. I'm pre-loading a handful of graphics, and there's not enough memory for two instances of the application to be running at the same time so it's crashing because the 1st instance of the application was not cleaned up properly.

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

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

发布评论

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

评论(1

同尘 2024-09-23 19:09:58

您有几个模拟器,所有模拟器都只运行这个应用程序,关闭它并再次启动它。
您的 Android 设备同时运行多个进程,例如后台同步、Facebook 通知、Twitter 通知、日历同步、联系人同步等。

查看此问题的一种方法是尝试在不同的模拟器上模拟 Android 设备状态,并查看是否会在模拟器上遇到相同的错误。使用一些在后台同步的应用程序和其他使用大量内存的应用程序。然后,您就有了一个模仿现实世界的测试环境,并且您可以将应用程序更改为不会崩溃的状态。也许尽可能缩小图像大小以减轻内存使用量。

请记住,您永远不能强制垃圾收集器启动。你只能告诉系统可以收集这个垃圾。

You have several emulators, all running just this app, closing it and start it again.
Your Android device has several processes running the same time, like background sync, Facebook notification, Twitter notification, Calendar sync, Contacts sync and the like.

One way to look at this is to try to mimic your Android device state on your different emulators, and see if you can get the same error on the emulators. Use some apps that sync in the background and others who use a lot of memory. Then you have a testing environment that mimics the real world, and you can change your app up to a state where it doesn't crash. Maybe downsize the images as much as you can to ease memory usage.

Remember, you can never force the Garbace Collector to start. You can only tell the system that it is possible to collect this garbage.

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