English 中文(简体)
我的《名单》短信正在泄露记忆。 我做了什么错误?
原标题:My Simple ListView app is leaking memory. What am I doing wrong?‏

首先,我首先把这交给了甲状腺 go集团,但是,它的温和和和我不敢肯定,要在这里展示这样希望的人,需要多长时间才能帮助。

I created a simple app with a ListView following the ListActivity examples I found on the net.

The app has 2 activities with the first having a button to create the second. When i hit the close button on the second activity I would like it to release its memory (or at least allow it to be garbage collected). Currently it will never release.

I must be doing something wrong here because the MyListActivity never gets released. Can anyone tell me if I am doing something wrong with the way my activities are created/destroyed? or if my usage of the ListView is wrong?

感谢。

My App as a zip -

Screen Shot of Eclipse MAT showing the list activity never releasing memory - www.mediafire.com/?qr6ga0k

public class MyListActivity extends ListActivity {  
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listlayout);        
    ListAdapter ada = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, GENRES);               
    setListAdapter(ada);    
}

@Override
public void onDestroy()
{                   
    super.onDestroy();
    System.gc();
}

public void ClickHandler(View target)
{
    switch (target.getId())
    {
        case R.id.LL_Btn1:
            finish();
            break;
    }
}   

private static final String[] GENRES = new String[] {
    "Action", "Adventure", "Animation", "Children", "Comedy", "Documentary", "Drama",
    "Foreign", "History", "Independent", "Romance", "Sci-Fi", "Television", "Thriller"
};} 

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

public void ClickHandler(View target)
{
    switch (target.getId())
    {
        case R.id.M_Button01:
            Intent intent = new Intent();
            intent.setClassName(MyListActivity.class.getPackage().getName(), MyListActivity.class.getName());         
            startActivity(intent);  
            break;
    }
}}
最佳回答

Eclipse MAT是原因。 新陈列演播室确实造成了这些问题。

问题回答

你们是否试图摆脱制度,看什么情况? 电话系统.gc()只是告诉国家机器公司启动垃圾收集工作——在进行这项工作时没有保证。

不能确定这样做会有所帮助,也不普遍建议这样做,但以下做法将杀害你在灾难中的工作:

System.runFinalizersOnExit(true); android.os.Process.killProcess(android.os.Process.myPid());

假设在网上发生。 现在,如果儿童活动要求,这实际上可能杀害你的主要过程(没有经过检测)。

WARNING:我一般不建议这样做,把它作为“hackly”做法,但如果你刚刚需要你的(或活动)来结束,那么这项工作就会奏效。 你们仍需要 de笑,以找出你们的记忆为何保持开放和吃不上。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签