退出应用程序时内存未清除

发布于 2024-12-21 13:57:28 字数 5969 浏览 2 评论 0原文

我浏览了一些文章,注意到有时应用程序退出时不会调用 onDestroy()。有时只调用 onPause()。我的全部事情是,当我使用后退按钮或 finish() 函数退出应用程序时,一切看起来都很好。当我尝试重新打开我的应用程序时,它说:

12-14 04:09:59.457: E/GraphicsJNI(996): VM won't let us allocate 3279360 bytes

我也将粘贴整个日志。问题是当它重新打开时,它会强制关闭。之后,我可以再次重新打开它。例如,每当我在 Eclipse 中重建它并通过模拟器运行它时,它都工作正常。但是,如果我在应用程序内关闭它并尝试重新打开它,那就是我遇到此内存问题的时候。我不确定什么没有被清除,我真的希望你们中的一个人能找到解决方案,或者至少能给我指出解决这个问题的正确方向,因为这真的让我很头疼。如果你们需要更多信息,请告诉我。谢谢。

12-14 04:09:59.457: E/GraphicsJNI(996): VM won't let us allocate 3279360 bytes
12-14 04:09:59.606: D/AndroidRuntime(996): Shutting down VM
12-14 04:09:59.646: W/dalvikvm(996): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-14 04:09:59.856: E/AndroidRuntime(996): FATAL EXCEPTION: main
12-14 04:09:59.856: E/AndroidRuntime(996): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ShotSlot/com.ShotSlot.ShotSlotActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.os.Looper.loop(Looper.java:123)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Method.invokeNative(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Method.invoke(Method.java:521)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-14 04:09:59.856: E/AndroidRuntime(996):  at dalvik.system.NativeStart.main(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.Activity.setContentView(Activity.java:1647)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.ShotSlot.ShotSlotActivity.onCreate(ShotSlotActivity.java:161)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-14 04:09:59.856: E/AndroidRuntime(996):  ... 11 more
12-14 04:09:59.856: E/AndroidRuntime(996): Caused by: java.lang.reflect.InvocationTargetException
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:170)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Constructor.constructNative(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
12-14 04:09:59.856: E/AndroidRuntime(996):  ... 21 more
12-14 04:09:59.856: E/AndroidRuntime(996): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.nativeCreate(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.content.res.Resources.loadDrawable(Resources.java:1709)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.View.<init>(View.java:1885)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.View.<init>(View.java:1834)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.ViewGroup.<init>(ViewGroup.java:285)
12-14 04:09:59.856: E/AndroidRuntime(996):  ... 25 more

I have looked through a few articles around and notice that sometimes onDestroy() is not called when an app is exiting. Sometimes only the onPause() is called. My whole thing is that when I exit my app with the back button OR the finish() function, everything looks fine. When I attempt to reopen my app, it says:

12-14 04:09:59.457: E/GraphicsJNI(996): VM won't let us allocate 3279360 bytes

I will paste the entire log as well. The thing is when it reopens, it force closes. After that, I can reopen it again. For example, whenever I rebuild it in Eclipse and run it through the emulator, it works fine. But if I close it inside the app and try to reopen it, that is when I get this memory issue. I am not sure what is not being cleared out and I really hope one of you guys has a solution or at least can point me in the right direction to resolve this because it is really giving me a headache. If you guys need more info, please let me know. Thanks.

12-14 04:09:59.457: E/GraphicsJNI(996): VM won't let us allocate 3279360 bytes
12-14 04:09:59.606: D/AndroidRuntime(996): Shutting down VM
12-14 04:09:59.646: W/dalvikvm(996): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-14 04:09:59.856: E/AndroidRuntime(996): FATAL EXCEPTION: main
12-14 04:09:59.856: E/AndroidRuntime(996): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ShotSlot/com.ShotSlot.ShotSlotActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.os.Looper.loop(Looper.java:123)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Method.invokeNative(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Method.invoke(Method.java:521)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-14 04:09:59.856: E/AndroidRuntime(996):  at dalvik.system.NativeStart.main(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.Activity.setContentView(Activity.java:1647)
12-14 04:09:59.856: E/AndroidRuntime(996):  at com.ShotSlot.ShotSlotActivity.onCreate(ShotSlotActivity.java:161)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-14 04:09:59.856: E/AndroidRuntime(996):  ... 11 more
12-14 04:09:59.856: E/AndroidRuntime(996): Caused by: java.lang.reflect.InvocationTargetException
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.widget.RelativeLayout.<init>(RelativeLayout.java:170)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Constructor.constructNative(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
12-14 04:09:59.856: E/AndroidRuntime(996):  ... 21 more
12-14 04:09:59.856: E/AndroidRuntime(996): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.nativeCreate(Native Method)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.content.res.Resources.loadDrawable(Resources.java:1709)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.View.<init>(View.java:1885)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.View.<init>(View.java:1834)
12-14 04:09:59.856: E/AndroidRuntime(996):  at android.view.ViewGroup.<init>(ViewGroup.java:285)
12-14 04:09:59.856: E/AndroidRuntime(996):  ... 25 more

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

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

发布评论

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

评论(1

长途伴 2024-12-28 13:57:28

尝试查看 DDMS,它有一个“堆”选项卡,可以告诉您内存分配情况。

窗口>开放视角>其他...

然后选择 DDMS

编辑

在我的一个应用程序中,我在“退出”按钮中设置了此设置,它会清除后台堆栈并启动应用程序中的第一个活动,只需将 Main.class 替换为您的第一个活动名称即可。然后,一旦您点击后退按钮,应用程序就会退出

        Intent intent = new Intent(this, MainMenu.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);

Try looking in DDMS, it has a Heap tab that tells you the memory allocation.

Window > Open Perspective > Other...

Then choose DDMS

EDIT

In one of my apps, i have this set in a Quit button, it clears the backstack and starts the first activity in your app, just replace Main.class with your first activitys name. Then once you hit the back button the app exits

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