O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Memory leak example

Let's explore an example of what the memory leak can look like. For this, we will create MockActivity with this content:

public class MockActivity extends AppCompatActivity {    private String[] bigArray = new String[10000000];    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_mock);        bigArray[0] = "test";        Log.i("APP", "Activity Created");    }    @Override    protected void onDestroy() {        Log.i("APP", "Activity Destroyed");        super.onDestroy();    }}

We will start this Activity from MainActivity by adding a button for testing purposes in its layout:

<Button    android:id="@+id/start_another_activity_button"    android:layout_width="wrap_content"    android:layout_height= ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required