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

  • Home
  • SEARCH
  • 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 6349167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:33:46+00:00 2026-05-24T21:33:46+00:00

I have read Android’s Developers Guide on Designing for Performance. I am just wondering

  • 0

I have read Android’s Developers Guide on Designing for Performance.

I am just wondering that if I have a large object, that I cannot avoid creating (which is expensive ) , it seems logical that I want to deallocate it immediately when I know I am done with it.

There seems to be no way of doing this.

Some suggest setting it to null so it will be immediately GC by the system, will this be truely “immediate”? Because if the system (Dalvik VM) has the option to NOT deallocate the large object that I just set to null, then setting it to null is not at all a solution.

Is it correct to say that setting it to null will ENCOURAGE and SPEED up GC?

Is this approach a “good enough” way to optimize Apps performance? Or is it worth going the extra mile (if at all possible ) , to force GC whenever applicable to squeeze the best performance out of any Android device?

  • 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-05-24T21:33:46+00:00Added an answer on May 24, 2026 at 9:33 pm

    I don’t think you should worry to the granular details when GC is executed as we don’t have control over when gc gets called. Even calling gc() will not guarantee a collection. Per documentation from System.gc()

    Indicates to the virtual machine that it would be a good time to run the garbage collector. Note that this is a hint only. There is no guarantee that the garbage collector will actually be run.

    In developing the application with large object allocation I would worry about the following instead:

    1. Upon allocating the large object and subsequently after exit the scope of life cycle of that object, do I see it get reclaimed by the GC in later Activities? This could be easily checked by running dumpsys meminfo with adb shell. You basically check after deallocation if the memory is properly garbage collected typically signify by large spike and drop afterwards
    2. Check if this large object has a clear path to GC. You could do this by checking the reference path of this object via dumping the hprof and check it in Memory Analyzer. If it does, you are safe as the GC will smart enough to collect.
    3. After I allocate this large object, do I have enough padding in my heap to execute subsequent activity? If the object is too large, there is a chance that GC is not fast enough to collect it (this is actually related to your point) and the memory consumption from subsequent activity combined with the left over from the previous ones might actually cause out of memory error. Setting null with a clear path to GC will help to ensure that this object will get GC’ed appropriately. I admit this is a problem, but my view is if this becomes a problem, we might have to relook on how this particular section is designed and see if we could do any optimization on it.
    4. Implement clean up on the activity via onDestroy as necessary and make sure the Activity is not referenced by others so it could get properly garbage collected. For example: we often pass activity context around forgetting that it will hold its reference. Things like calling recycle() on bitmap should also help. Remembering these points should help preparing more space in the case of #3 happens
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/reference/android/util/DisplayMetrics.html and I somehow left with a gap here.
I have read that it will allow creating an Android app without (much) programming
I have read that I can test android application on a emulator, but I
I thought I have read somewhere that the accuracy of Android's GPS is about
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I have read a lot that LISP can redefine syntax on the fly, presumably
I have read that using database keys in a URL is a bad thing
I have read on Stack Overflow some people that have converting to C#2.0 to
I have read (or perhaps heard from a colleague) that in .NET, TransactionScope can
I have an app that is available from the Android Market. Some users have

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.