Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:32:58+00:00 2026-06-17T18:32:58+00:00

In a simplified version of my app, I have two activities, A and B.

  • 0

In a simplified version of my app, I have two activities, A and B. Actvity A starts B, and after some work B calls finish(). Using the Memory Analyzer Tool on most devices (Galaxy Nexus running 4.2, Droid 4 running 4.0.4, and Droid 2 running 2.3.4) shows no trace of activity B, which is what I expected.

But on Samsung S3 running 4.1.1, MAT shows activity B objects still around, due to paths to the following GC roots (weak/soft references excluded):

Class Name                                                        | Shallow Heap | Retained Heap
-------------------------------------------------------------------------------------------------
com.myCo.myApp.ActivityB  @ 0x42720818                            |          264 |         3,280
|- <Java Local> java.lang.Thread @ 0x4271cf60  Thread-21941 Thread|           80 |        52,264
|- mOuterContext android.app.ContextImpl @ 0x426adf68             |          104 |           784
    |  '- mContext android.media.AudioManager @ 0x428e49a0        |           48 |           152
-------------------------------------------------------------------------------------------------

Every time I start and stop activity B, MAT shows another instance of activity B’s memory footprint. And the more I open/close activity B, the bigger the memory footprint reported in logcat. Forcing a GC through MAT does not remove the references to activity B memory.

I have three questions.

  1. Why is the memory/GC behavior different across the different devices?

  2. On S3, will the OS eventually come back and GC the stranded activity B objects (in other words, should I not worry about it because Android will clean it up before a crash)?

  3. If not, where do the Thread and AudioManager references come from, and how would I clear them?

Thanks to any experienced “leak hunters” out there!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:32:59+00:00Added an answer on June 17, 2026 at 6:32 pm

    UPDATE: In order to see if the “stranded” memory left by activity B is in fact a problem, I created a loop between activities A and B:

    --- A calls startActivityForResult() on B
    --- B calls finish()
    --- onActivityResult() in A calls B again, etc...
    

    I let it fly for about 15k iterations, and the program did not crash. So even though the JVM on this phone and OS version (Samsung S3, 4.1.1) leaves references to class B in memory, even after activity B calls finish(), it appears there is a later clean up of some kind, as the number of references to the B class did not monotonically increase during the test.

    In fact, I generated several heap dumps during the test and never saw more than about 100 instances of the B class — as opposed to the 15k I would expect to see if there were no other clean up. GC statements in the logcat also showed memory use going both up & down, in spite of the large number of invocations of activity B.

    My conclusion is that I should not worry about the existence of class B references in the heap dump after finish() calls, because it appears that the JVM used on this phone/Android version does some kind of deferred clean up.

    Note: This is my inference based on the test I ran, so if anyone knows differently please share. Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simplified version of my app in XAML: <UserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:mc=http://schemas.openxmlformats.org/markup-compatibility/2006
Here is simplified version of my requirement I have a java class say Processor
Here is a simplified version of what I have (not working): prog.h: ... const
This is the simplified version of the problem: We have a table on an
I'm working on an app. Here I describe a simplified version of a strange
I'm currently using commons-net library for FTP client in my app. I have to
I have a web app that I am building using asp mvc with nhiberante
I've got a document based App using Core Data, and have a tableView which
Very simplified version of my code: #include <iostream> #include <string> using namespace std; int
I have created a Windows 8 Store App using C# / XAML. My interface

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.