问题描述
我有一个启动一个活动
的的AsyncTask
(称为WorkerClass),并从AsyncTask的我添加一个 BaseAdapter
我的 GridView控件
:
I have an activity
which starts an asynctask
(called WorkerClass) and from the asynctask i add an BaseAdapter
to my GridView
:
我从我的活动启动AsyncTask的:
I start the AsyncTask from my Activity:
if(gallery == null || switchScaleMode == true) {
myWorkerClass = new WorkerClass(myActivity.this, width, scaleButtonText);
myWorkerClass.execute();
}
画廊是显示图像在我的GridView的可绘制列表。我知道这是非常糟糕的把整个活动的背景下另一个类..但我需要它来获取在 WorkerClass(AsyncTask的)访问2次
。所以我的第一个问题,它会prevent我的内存泄漏,如果我只是把2次到 WorkerClass
,而不是整个活动?
Gallery is a drawable List which Shows Image in my gridview. I know it's really bad to put the whole activity context to another class.. But i Need it to get Access to 2 views in the WorkerClass(AsyncTask)
. So my first question, would it prevent my Memory leak if i just put the 2 views to the WorkerClass
instead of the whole activity?
为什么我知道我有一个内存泄漏我的应用程序?
我开始更新堆在DDMS我的应用程序进程,得到了如下结果:
I started Update Heap in the DDMS for my APP-Process and got following results:
在启动至完全加载:
对于我来说,这看起来像一个HIGHT量,如果有> 90%开始后内存使用。
For me this Looks like a hight amount if there is >90% of Memory usage after start..
现在,当我转动我的设备好几次我得到这个:(通知:我只启动 WorkerClass
并添加适配器到 GridView控件
有一次,在启动时。因为我不希望重新计算(将图像等),每次用户旋转(时间consumpting)。
Now when i rotate my device several times i get this:(notice: i only launch the WorkerClass
and adding the Adapter to the GridView
one time, at Startup. Because i don't want to recalculate(getting Images and so on) every time user is rotating (time consumpting).
所以,如果我再次旋转我的设备并再次我得到了一个AsyncTask的内存溢出异常。即使是我只有一次启动它。(所以必须有一个对象,它会导致OOM ??的娱乐某种)
So, if i rotate my device again and again i get a Out Of Memory exception in the AsyncTask. Even that i only start it once.. (so there must be some Kind of recreation of an object which cause a OOM ??)
我不明白的是,如果我超过了DDMS按钮 GC
做GC我得到:
What i don't understand is that if i do a GC over the Button GC
in the DDMS i get:
因此,这是使用我的进程的内存量有所增加?但不应该在GC释放使用的内存?
So the amount of Memory which is used by my process has increased? But shouldn't the GC releasing used Memory?
最后一个问题:我试图从日食是 MAT (内存分析工具)的工作。但是,这只是启动后,工作在 DDMS
我的应用程序。如果我服用堆转储前几次旋转
快照日食并不做任何事情。没有错误,也没有动作。我唯一注意到的是,我无法启动堆转储
再次出现以下错误:
The last Problem: I tried to work with MAT (Memory Analyzer Tool) from eclipse. But this only works after Startup my app in the DDMS
. If i rotate it several times before taking a Heap Dump
"Snapshot" eclipse doesn't do anything. No error, but also no Action. Only Thing i noticed is that i can't start Heap Dump
again with the following error:
12-07 15:09:52.739: E/jdwp(1109): Failed sending b-req to debugger: Invalid argument (67536832 of 96983113)
12-07 15:09:53.759: E/jdwp(1109): Failed sending reply to debugger: Try again
请理解,我并不怎么让我的整个code公众。如果你告诉我你想看到我会尽我所能,具体是什么..
Please understand that i don't what to make my whole code public. If you tell me specifically what you want to see i'll try my best..
更新
所以,现在我有一个堆转储一些旋转后,这是输出:
So now i got a Heap Dump after some rotates and this is the Output:
我实例化的EditText和GridView在我的活动,并在我的 WorkerClass
。因为这些都是我在 WorkerClass
为什么我把我的活动 - 语境
极品仅有的两个意见 WorkerClass
。
I instantiate EditText and GridView in my Activity and in my WorkerClass
. Because These are the only two views which i Need in my WorkerClass
and why i put my Activity-Context
to the WorkerClass
.
所以将它解决我的问题是,如果声明并仅在活动实例并将其传递给 WorkerClass
。
So will it solve my Problem is if declare and instantiate them only in the Activity and pass them to the WorkerClass
.
更新2
该DominatorTree:
The DominatorTree:
推荐答案
是已加入的EditText的textwatchers。由于在一个EditText听众在一个ArrayList内部保存,他们不断收到追加导致泄漏的列表。您尝试添加新的之前从EditText上移除或清洁所有的听众。应修复泄漏。
after analyzing your dumps it seems like the problem is the textwatchers that have been added to the edittext. Since listeners in an edittext are saved internally in an arraylist they keep getting appended to the list leading to a leak. try to remove or clean all listeners from the edittext before you add new ones. that should fix the leak.
这篇关于preventing我的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!