Sunday, 15 September 2013

Memory leak - multiple instance of activity

Memory leak - multiple instance of activity

I've got a couple of activities. The thing is the app is running out of
memory. I tried to gc.clean() in all activities (in onDestroy), null
references, launchMode="singleTop" but without any success.
In MAT i've found out that I have multiple objects of the same activity
and it a default behaviour, if I'm not mistaken.
If i launch at first time, for example i will have main activity: 1, if i
will quit and launch again i will have 2 instance.
that the VM budget just grow and make force close dialog.
Example of my code:
public class Splash extends Activity { private RelativeLayout splash_layout;
private RelativeLayout welcome_message_layout;
private TextView welcome_message_text;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splash_layout);
splash_layout = (RelativeLayout)findViewById(R.id.splash_layout);
welcome_message_layout =
(RelativeLayout)findViewById(R.id.welcome_message_layout);
welcome_message_text = (TextView)findViewById(R.id.welcome_message_text);
if(ref.getBoolean("LANGUAGEMODECHANGE",false))
{
welcome_message_layout.setBackgroundResource(R.drawable.welcome_message);
welcome_message_text.setText(getString(R.string.welcome));
switch(ref.getInt("LANGUAGEMODENUMBER",Consts.DEFAULT))
{
case Consts.HEBREW:
splash_layout.setBackgroundResource(R.drawable.welcome_hebrew);
break;
case Consts.ENGLISH:
splash_layout.setBackgroundResource(R.drawable.welcome_english);
break;
case Consts.RUSSIAN:
splash_layout.setBackgroundResource(R.drawable.welcome_russian);
break;
case Consts.ARABIC:
splash_layout.setBackgroundResource(R.drawable.welcome_arabic);
break;
default:
splash_layout.setBackgroundResource(R.drawable.bg);
break;
}//close switch
}
}//close onCreate
}//close Splah
Where is the leak?

No comments:

Post a Comment