-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fb mem leak + remove BuildConfig.DEBUG #442
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
Conversation
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
Signed-off-by: Alex Saveau <[email protected]>
# Conflicts: # auth/src/main/java/com/firebase/ui/auth/provider/FacebookProvider.java
…-leak # Conflicts: # auth/src/main/java/com/firebase/ui/auth/provider/FacebookProvider.java
// a HashMap in the CallbackManager instance, sCallbackManager. | ||
// Because FacebookProvider which contains an instance of an activity, mCallbackObject, | ||
// is contained in sCallbackManager, that activity will not be garbage collected. | ||
// Thus, we have leaked an Activity. |
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.
Do we want to keep this explanation? It's a bit lengthy and could probably be replaced with // Fixes activity leaks
.
Here is the Facebook code in question:
CallbackManager.Factory.create()
public static CallbackManager create() {
return new CallbackManagerImpl();
}
loginManager.registerCallback(sCallbackManager, ***this***);
->
/**
* Registers a login callback to the given callback manager.
* @param callbackManager The callback manager that will encapsulate the callback.
* @param callback The login callback that will be called on login completion.
*/
public void registerCallback(
final CallbackManager callbackManager,
final FacebookCallback<LoginResult> callback) {
if (!(callbackManager instanceof CallbackManagerImpl)) {
throw new FacebookException("Unexpected CallbackManager, " +
"please use the provided Factory.");
}
((CallbackManagerImpl) callbackManager).registerCallback( // sCallbackManager is storing callback into itself
CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(),
new CallbackManagerImpl.Callback() {
@Override
public boolean onActivityResult(int resultCode, Intent data) {
return LoginManager.this.onActivityResult(
resultCode,
data,
***callback***);
}
}
);
}
->
private Map<Integer, CallbackManagerImpl.Callback> callbacks = new HashMap<>();
public void registerCallback(int requestCode, Callback callback) {
Validate.notNull(callback, "callback");
callbacks.put(requestCode, ***callback***); // Callback is now in callbacks HashMap
}
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.
Thanks for the super-detailed investigation. I am fine with the long comment, it makes people more scared to undo your fix.
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.
Thanks again!
} else { | ||
try { | ||
String email = object.getString("email"); | ||
mCallbackObject.onSuccess(createIDPResponse(loginResult, email)); | ||
FacebookProvider.this.onSuccess(email, loginResult); |
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.
Any reason this branch has FacebookProvider.this
but the failure branch does not?
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.
Nope.
// a HashMap in the CallbackManager instance, sCallbackManager. | ||
// Because FacebookProvider which contains an instance of an activity, mCallbackObject, | ||
// is contained in sCallbackManager, that activity will not be garbage collected. | ||
// Thus, we have leaked an Activity. |
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.
Thanks for the super-detailed investigation. I am fine with the long comment, it makes people more scared to undo your fix.
Signed-off-by: Alex Saveau <[email protected]>
Yes! This is the last leak I've encountered so once this gets merged, FirebaseUI will finally be leak free!
The leak will occur when the
startLogin()
method is called inFacebookProvider
: