-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TIMOB-13392] Android: fix TabGroup fragment memory leaks, fix maps in tabs including when acti... #6008
Conversation
Thank you. Is this part of https://jira.appcelerator.org/browse/TIMOB-13392, or is it part of a new ticket? |
This is a bunch of fixes for that issue. I'm currently writing up the comments for it, hopefully all will be clear in 5 minutes :) |
{ | ||
// Set the layout proxy here since it's not ready when we indirectly call it inside contextCreated() | ||
setLayoutProxy(window); | ||
|
||
// The UIWindow needs to be created before we run the script | ||
activityWindow = new TiUIActivityWindow((TiActivityWindowProxy)window, this, getLayout()); | ||
super.windowCreated(); | ||
super.windowCreated(savedInstanceState); | ||
} | ||
|
||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have changes like this in several files to enable activities to save and restore arbitrary data structures. This was absolutely required for the tab group, which needs to store/retrieve the IDs of the fragments in the FragmentManager in order to prevent leaks.
See comments in the code for explanation of what was done. |
return POSITION_NONE; | ||
while (fragmentTags.size() <= position) { | ||
fragmentTags.add(null); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is a bit off here
Hey Mark, I'm running your updated test case in the ticket as I'm trying to reproduce the memory leak problem. I have developer option 'dont keep activities' on, so the activities are destroyed every time i switch tabs. I'm not seeing any significant movement of the heap via DDMS after scrolling through all 5 tabs ~20-30 times. |
@hieupham007 put the following code in android/modules/ui/src/java/ti/modules/titanium/ui/widget/tabgroup/TiUIActionBarTab.java in the TabFragment class, open and close window 2 several times (with don't keep activities on) and watch over time how many fragments are created (in the 3.5.0 master).... This is what happens when we create fragments every time, instead of reusing the fragments that are already in the FragmentManager.
|
} else { | ||
transaction = manager.beginTransaction(); | ||
} | ||
FragmentTransaction transaction = manager.beginTransaction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check was not necessary and in fact was crashing the app on occasion due to https://code.google.com/p/android/issues/detail?id=42601 . The crash would occur because tabFragment.getChildFragmentManager()
would sometimes be called prior to tabFragment.onActivityCreated occurring (although getSupportFragmentManager
works fine at that point). The reason the 3.5.0 master works is that it does not set the ID "tabcontent", so we never called getChildFragmentManager
... However testing shows that we don't need it, and the sample app works perfectly without it. If we ever want getChildFragmentManager
to be used, then it can only be called after fragment.onActivityCreated (unless Google fixes their bug). Nevertheless, it's not needed at this point.
Modified per comments, documented |
Any update on the review for this? All comments taken care of and no issues found with any test I tried, with latest fixes. |
description: | | ||
If true, when clicking the tab the page transition is animated, false otherwise. | ||
platforms: [android] | ||
since: 3.4.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be since 3.5.0 .
@pingwang2011 fixed the doc |
Functionally tested with KitchenSink and test cases in the ticket. Looks good to me. |
Can this be merged please, if there are no outstanding issues? Thanks. |
@ingo @hieupham007 @pingwang2011 |
👍 Great work! |
…ctivity restored, etc
0a98412
to
80604a4
Compare
I've created a new PR to resolve conflicts: #6414 |
This fixes and improves the initial commit using the ViewPager for the TabGroup.
Issues solved:
In general, this is very well tested, since it built on the testing done for the previous commit which was already heavy. Specifically tested: removing and adding tabs, using a map in the tabs, disabling and enabling tabs, doing all the previous then opening a new window (destroying the tab group activity), and then coming back to the tab group - all works splendidly and no memory leak.
Please merge ASAP since this fixes serious issues in the previous commit. Thanks!