Reputation: 861
I am building a small app which yesterday worked just fine, but today after adding a button did not. I reverted all my changes but I still get the same error, that the app runs out of memory. This is the code and stack trace:
public class MainActivity extends AppCompatActivity {
private MainActivity mainActivity = new MainActivity();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}}
Logcat: http://pastebin.com/UdAFp32h
I did find something interesting in the Logcat:
03-29 14:34:42.067 20964-20964/com.example.antongustafsson.csnappen
A/art:art/runtime/runtime.cc:291] at
com.example.antongustafsson.csnappen.MainActivity.<init>(MainActivity.java:15)
03-29 14:34:42.067 20964-20964/com.example.antongustafsson.csnappen
A/art: art/runtime/runtime.cc:291] at
com.example.antongustafsson.csnappen.MainActivity.<init>(MainActivity.java:16)
03-29 14:34:42.067 20964-20964/com.example.antongustafsson.csnappen
A/art: art/runtime/runtime.cc:291] at
com.example.antongustafsson.csnappen.MainActivity.<init>(MainActivity.java:16)
03-29 14:34:42.067 20964-20964/com.example.antongustafsson.csnappen
A/art: art/runtime/runtime.cc:291] at
com.example.antongustafsson.csnappen.MainActivity.<init>(MainActivity.java:16)
03-29 14:34:42.067 20964-20964/com.example.antongustafsson.csnappen
A/art: art/runtime/runtime.cc:291] ... **repeated 261584 times**
It looks like I got a infinite loop going, except I do not. Does anyone know anything I could try? Why does this error just randomly occur?
Upvotes: 0
Views: 91
Reputation: 165
For your future issues with memory: Try to use Eclipse Memory Analyzer Tool to profile your memory and track potential memory leaks
Upvotes: 0
Reputation: 7357
Your class MainActivity
repeaditly creates new instances of MainActivity
, since the variable declaration and initalization
MainActivity mainActivity = new MainActivity();
will lead to an endless recursion that does create instances of MainActivity
.
Upvotes: 9