Book Image

Testing and securing android studio applications

Book Image

Testing and securing android studio applications

Overview of this book

Table of Contents (18 chapters)
Testing and Securing Android Studio Applications
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Heap


The Heap tab stores all new objects created in the application. The garbage collector (GC) deletes the objects that are not referred anymore, releasing unused memory. The Heap tab displays the heap usage for a selected process.

To illustrate the working of this tool, run the following example. Create a new basic project with a main layout and a main activity in Android Studio. Add a button to the main layout, for example, Start Memory Consumption. Create a new method to be executed when the button is clicked and add the following code to the method:

public void memoryConsumption(View v){
  list = new ArrayList<Button>();
  for (int i = 0; i <= 1000; i++) {
    list.add(new Button(this));
  }
}

Finally, add the declaration of the list as a global variable in the activity. This way, you are preventing the GC to release the memory that stores the list after the method finishes its execution. The declaration of the list as a global variable in the activity is shown as follows:

private...