在Android Memmory问题 [英] Memmory issue on android

查看:101
本文介绍了在Android Memmory问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在后台保存图像时再转移到GridView的全画面我有一个内存问题。

I have a memory issue when saving images on the background then transferring to gridview full of pictures.

所以我的应用程序是如何工作的:

So how my application works:

活动一显示一些图片,(无痛加载在这里启用)
活动二保存在SD卡中的图像

Activity one "Shows a bunch of images" (Painless loading is enabled in here) Activity two "Save images in the sd card"

这个问题我有谎言与活动二,因为它进入活动之一。当项目被保存在显示没有图像的背景。

The problem I have lies with activity two as it goes to activity one. When items gets saved in the background which shows a lack of images.

我曾尝试:

我试图转移到活动的人之前先调用System.gc()。

I have tried to call System.gc() before transferring to activity one.

我试图创建一个方法,改变变量设置为NULL。(强制垃圾收集)

I have tried to create a method and change the variables to null.(Force a garbage collection)

我的尝试均告失败。所以,如果有人可以给我什么将是我的优化我将不胜感激,选择一个更好的主意。

My attempts were unsuccessful. So if someone could give me a better idea on what would be my options for optimizing I would be grateful.

推荐答案

昨天我找到了问题的原因。问题是我加入的AsyncTask类中,甚至在完成等级来传送下一个活动后的项目。异步类莫名其妙地保存它的项目,因为我使用含上下文ProgressDialog我的异步类中,并根据此<一个href=\"http://stackoverflow.com/questions/2726494/what-happens-on-activity-finish-with-asynctask-still-running-in-background\">comment.

I found the reason for the problem yesterday. The problem was me adding the items inside the AsyncTask class and even after completing the class to transfer the next activity. The async class somehow saves its item since I am using a ProgressDialog containing a context within my async class and according to this comment.

这将保留对活动的引用,被当作垃圾收集保持活动......除非它是一个静态内部类或完全独立的类,它没有提及活动或任何指向活动

"It will hold onto a reference to the Activity, keeping the Activity from being garbage-collected...unless it is a static inner class or fully independent class that has no reference to the Activity or anything that points to the Activity"

通过评论 CommonsWare

这篇关于在Android Memmory问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆