title: Memory Management in Android
body: <p>So, I tested my game out for the first time with the Monkey test. I managed to go about 3 minutes without a crash, but I ended up crashing with an out of memory error, and I'm trying to figure out how I might make it better.</p>
  
  <p>My program is structured as follows:</p>
  
  <ul>
  <li>There is a front screen which will start an activity. </li>
  <li>The secondary activity is where most of the action is, and also where I crashed.</li>
  <li>I crash on an inflate command</li>
  <li>My game forces portrait mode, it was easier to make 1 layout than 2 work...</li>
  <li>There are a number of class variables associated with my secondary activity. I'll include the non-static ones below. I've also included some kind of a clue for those things which aren't obvious as to what they are.</li>
  </ul>
  
  <p>What I'm wanting to know is how I can improve the memory management of my program so it won't crash. I suspect that I need to manually delete some of these variables, but I'm not sure what the right place to do so is. Thanks!</p>
  
  <pre><code>private Level_Score_bar score_bar; // Custom view
  private number_viewer num_viewer; // Custom view
  private number_pad num_pad;       // Custom View
  private int time,score,level,num_remaining,current_var,change_loc,time_remaining;
  private ArrayList&lt;Integer&gt; the_key;
  private ImageView Number_to_select;
  private Boolean update_viewer; 
  Random rseed;
  Vibrator bzzz;
  long ctime;
  private Activity self=this;
  
  private SharedPreferences prefs;
  private Editor prefs_edit;
  </code></pre>
  
  <p>The out of memory occurred</p>
  
  <pre><code>   setContentView(R.layout.level_layout);
  </code></pre>
  
  <p>This layout is rather complex, containing several image views, buttons, text views, etc.</p>