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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:00:18+00:00 2026-05-29T09:00:18+00:00

Is the behavior similar to the way Activities work? For example with Activities it

  • 0

Is the behavior similar to the way Activities work? For example with Activities it works like this:

Activity A starts Activity B, while B is on screen, the system is able to remove A from memory if it is needed by the system. Upon pressing BACK, A will be recreated into memory as if it never left in the first place.

I have looked for a clear explanation of what happens memory wise with Fragments and haven’t found anything. Does it work the same way? For example:

Activity C has Fragment F in its layout. Then, at some point F is replaced by Fragment G, but F is kept in its back stack.

Will F stay in memory until the C is killed or can it be removed by the system as needed?

Really what I am asking is whether or not I run the risk of running out of memory if I have a back stack of complicated Fragments in a single Activity?

  • 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-29T09:00:19+00:00Added an answer on May 29, 2026 at 9:00 am

    Take a look at this: BackStackRecord.Op.fragment

    That is how fragments are stored in the back stack. Note the live reference, neither WeakReference nor SoftReference are used there.

    Now this: FragmentManagerImpl.mBackStack

    That is where manager stores the back stack. Simple ArrayList, also, no WRs or SRs.

    And finally this: Activity.mFragments

    That is the reference to the fragment manager.

    GC can only collect objects that have no live references (are not reachable from any thread). That means, until your Activity is destroyed (and so, FragmentManager reference is gone), GC will not be able to collect any of the Fragments in the back stack.

    Note that when Activity is destroyed and retains state (like when you turn the device to landscape mode), it doesn’t retain actual Fragment objects in the stack, only their states – Fragment.FragmentState objects, i.e. actual fragments in the back stack are re-created every time activity gets re-created with retained state.

    PS So, in short: Yes, you can run out of memory by adding Fragments to back stack as well as by adding too many views to view hierarchy.

    UPD Considering your example, F will stay in memory until C is killed. If C is killed and then resurrected with different configuration – F will be destroyed and reincarnated in a different object as well. So, F‘s memory footprint is around until C loses state or back stack is cleared.

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

Sidebar

Related Questions

I'd like to have a settings bundle behavior similar to the iPhone WiFi settings.
I'm developing an Android Application that has three very similar Activities. I would like
Is there a reasonable way in Python to implement mixin behavior similar to that
I want to implement a docking library in wpf with behavior similar to Adobe
I want to create a similar behavior to the data reader class but for
I have developed some classes with similar behavior, they all implement the same interface.
Do you know any implementation / technique which would provide similar behavior as Viewstate
An example of unspecified behavior in the C language is the order of evaluation
I like the way in C# where you can write an extension method, and
I need a text field very similar in behavior to Gxt's NumberField. Unfortunately I

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.