Activity instance remains in the memory after onDestroy()


I know that this topic has been already beaten enough, but I still don't understand completely if Android System has fine behavior in following case:

I created small app consists of two classes, here is the code:


public class Main extends Activity { private Button bv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bv = (Button) findViewById(R.id.hello_txt); bv.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Main.this, Main2.class); startActivity(i); } } ); } }


public class Main2 extends Activity { private TextView countOfActivities; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); countOfActivities = new TextView(this); setContentView(countOfActivities); countOfActivities.setText("Count of Activities: " + getInstanceCount()); } }

When I clicked on the button from first activity several times, I get that even after pressing BACK button that should call second Activity's onDestroy() it's instance remains in the memmory.

Only after creating about 35 instances next click let me know, that GC cleared the memmory. I just want to completely be sure that it is normal system's behavior.

Following pictures from Emulator and LogCat

Button clicked 10 times

LogCat output after clicked


Yes, the system works fine. When you press the back button, your activity is removed from the activity stack.
onDestroy() may have been called, this doesn't mean that the instance was actually unallocated from the memory.



  • Could not copy “obj\\Debug\\{project}.dll” to “bin\\{project}.dll”
  • R independent columns in matrix
  • Creating msqrd or snapchat filters using javascript
  • call child function from parent in reactjs
  • How multiple executors are managed on the worker nodes with a Spark standalone cluster?
  • Problems with connecting bluetooth SPP in android?
  • How to get spesific error instead of Internal Service Error
  • Animated line plot with parallel processing
  • Oracle outer join with filter condition on the second table
  • How to get current TFS license type?
  • How to add a share button to the text selection bar for an EditText?
  • How do I handle a WebSocket close from the client in Yaws?
  • Select multiple fields with single group by in django
  • Having a custom repository with DBAL connection in Symfony 2 / Doctrine 2?
  • Why processBuilder in java hangs after 5 mins?
  • How do I link when building with llvm libraries?
  • List using with references, changes behavior when used as a member
  • Display variable as html in Google App Script?
  • can you use embedded ruby in custom javascript files in rails?
  • Tkinter tkMessageBox disables Tkinter key bindings
  • NoClassDefFoundError: com.google.gson.GsonBuilder when using google play services with microsoft azu
  • Unsupported ciphersuite TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
  • About global variables in Node.js
  • PHP: Need to close STDIN in order to read STDOUT?
  • Spotify cocoalibspotify offline status set to 1 but all tracks stuck at waiting
  • SQL Server version 612 , 655?
  • how to specify different css for ie
  • How can i move Clearcase dyamic/snapshot views to another host (Linux)
  • Floating parent div grows to hypothetical width of floating child div
  • How to use Streams api peek() function and make it work?
  • SpringBoot: Bypass OncePerRequestFilter filters
  • Spring Boot fails to start
  • Codeigniniter insert data through models and controller
  • Sign a Pdf using custom digital signature in Java
  • Spring Boot not autowiring @Repository
  • ARKit code issue {unknown error -1=ffffffffffffffff error: Task failed with exit 1}