My SimpleView List app is skipping memory. What am I doing wrong?

Firstly, I published this in the google android group at first, but moderated it, and I'm not sure how long it will take to appear there, so I hope someone here can help.

I created a simple ListView application after ListActivity examples that I found on the net.

The application has 2 actions with the first, which has a button to create the second. When I press the close button of the second operation, I would like it frees up its memory (or at least allows it to garbage collected). Currently it will never be released.

I have to do something wrong here because MyListActivity is never freed. Can someone tell me if I am doing something wrong with how my actions are created / destroyed? or if my use of ListView is wrong?

Thank.

My zip application is http://www.mediafire.com/?l26o5hz2bmbwk6j

Eclipse MAT screen shot showing 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;
    }
}}
+2
source share
3 answers

Eclipse MAT was the reason. The new Android studio does not cause these problems.

0
source

System.gc() , ? Calling System.gc() - , .

0

, , , onDestroy():

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

onDestroy. , (havn't ).

WARNING: I usually do not recommend doing this as a β€œhacker" way to do this, but if you just need to close your application (or action) after exiting, this will work. You still need to debug to find out why your application remains open and has memory.

0
source

All Articles