Will this cause memory leaks?
<p>Will the following code cause a memory leak? Essentially I switch between various layouts in my application using setContentView(), and I have member variables of my activity that maintain references to various views (buttons/textviews...) on the layouts. </p>

<p>Am I correct in thinking that if the activity class has a reference to a button and then changes layouts the layout wont be garbage collected because it will still hold a button reference? If this is the case, can I just null the button variable before changing layouts?</p>

<p>Thanks.</p>

<pre><code>public class MyApp extends Activity  {

    private Button startBtn;

    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

    // Set main layout
    setContentView(R.layout.main);

    startBtn = (Button) findViewById(R.id.startBtn);
    startBtn.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
                doStart();
            }

        }); 
    }

    private void doStart()
    {
        // Change to starting screen layout
        setContentView(R.layout.begin);

        /// .. Work with more views here and change layouts in a bit .. //
    }

}
</code></pre>
