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 8083031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:19:33+00:00 2026-06-05T17:19:33+00:00

I don’t want to create a vague question so I will try to make

  • 0

I don’t want to create a vague question so I will try to make this as clear as possible (Going to try my best).

I know garbage collection has been a grey area in programming for a very long time. I am not certain with the case of android or other mobile phones.

What I know of garbage collection in android:

  1. It collects class system class ojbects(Made by correction from an answer).
  2. Edit* “GC collects activity items only once the activity is destroyed. Activity lifecycle is driven by its attributes in the manifest, also by the flags of the intent that that launched it.” – Seva Alekseyev . As commenter said.
  3. You may force a garbage collection using “System.gc()” although this is not recommended as it may delete something important class item.

Now I obtained this information from stackoverflow(Now knowing that it is no longer a grey area for garbage collection)

Going to my question:

  1. How do you get this information about the process or generic information(book, internet article, etc.) about garbage collection from?
  2. If there is not answer for question 1 what are the other ways or methods that developers should be reminded when developing applications requiring the constant use of memory?
  • 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-05T17:19:34+00:00Added an answer on June 5, 2026 at 5:19 pm

    I’m not sure your information is correct.

    It collects class system classes.

    No. It collects instances of objects that are no longer reachable from any of the system roots. System roots include any static reference, any reference from a thread’s active stack frame, any active synchronization monitor, and anything held by a native piece of code (global or local). An object is considered live (and hence cannot be reclaimed) if there is a path from it to a root tracing the reference graph backwards. Any object that doesn’t not have a path to a root can be reclaimed by the garbage collector. Classes are referenced by a ClassLoader and are never reloaded and hence are not reclaimed by the system unless that ClassLoader is collected and all instances of those classes are collected. So Android never collects class system classes because that ClassLoader is never collected.

    It collects items from activity “only” if android manifest file states that the activity is either hasNoHistory or singleTop

    No. An activity is nothing more than an instance of an object. And when the reference to the activity is gone so goes all of the references it pointed to unless some other root points to that object. By setting singleTop=”true” you are only telling Android to instantiate a single instance of this activity, and all intents sent will be handle by that single instance. It doesn’t have any impact on GC. When an activity looses its path to a root it will be reclaimed regardless of what the settings on that activity were.

    You may force a garbage collection using “System.gc()” although this is not recommended as it may delete something important class item.

    No Garbage collection algorithms do not delete any live object. Under your definition above it implies GC can collect an object you were using which is incorrect. If it did that’s a big bug. That is also the beauty of Garbage Collection algorithms in that they are guaranteed to clean up garbage perfectly. If you are running out of memory the programmer has forgotten to remove a reference or you are being careless with your use of memory. The reason you aren’t suppose to call System.gc() is that you/your program has no clue when the best time is to reclaim memory. The garbage collector is trying to maximize the ratio of (the time your program runs) vs. (the time it spends collecting garbage). It keeps very detailed statistics and makes estimations about when its a good time to run garbage collection vs simply allocating more memory.

    It’s like cleaning your house. You can’t clean at all times because it makes doing things take longer sometime you have to let it get dirty (Like cooking). However, if you never clean your house it can take all day to clean it. So there is a balance that you must strike between how dirty can it become before cleaning it up takes longer than performing the task.

    This is why you shouldn’t calculate/guess/force GC in your program because Android has already implemented it for you, and will do a better job than you can ever hope to.

    What does this mean for you the developer?

    1. Let Android handle when GC should run.
    2. Clean up references to help the GC know when something can be reclaimed. Be very careful about static references, and never allow a static to hold a reference to an activity, service, etc to one.
    3. Don’t allocate lots of small amounts of short lived memory. This will force more GC time to clean up. By allocating memory conservatively you are by definition helping that ratio.

    Most of the time GC is very hands off. The only problems developers get into is not establishing boundaries for long living objects vs. UI objects. If a long living objects has a reference back to the UI that’s a place you’ll have to unregister or else you’ll leak memory. It’s ok for the UI to hold references to long living objects, but not the other way around.

    The real issue with Android is how much you make the garbage collector work. If you keep the amount of memory you are using small then the garbage collector doesn’t have big jobs it has to do. That doesn’t mean you should reuse objects or create object pools, etc. But, you should be aware of what statements are creating memory, and how long those objects live for.

    There are volumes of information on Garbage collection in general and particularly Java’s Concurrent Mark and Sweep garbage collector. Android’s garbage collector is not as performant, but it’s pretty darn good. Most of the time I don’t worry about GC unless there is a problem so it’s mostly hands off.

    And garbage collection isn’t a grey area. It’s very much well understood, and the industry has expanded the field quite a bit since Java was introduced in 1994.

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

Sidebar

Related Questions

I don't know whether this is really possible, but I'm trying my best. If
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't know if I worded the question right, but basically what I want to
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
I don't have much PHP experience and I want to know how to best
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
I don't know if this is a well known 'thing' or something new in

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.