Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Few memory leaks in Facebook SDK

I tried to make social module for my app, something like wrapper, that will contain Google+,Facebook and twitter integration templates.

Now I am working with Facebook SDK and decided to use LeakCanary in my app, after successful log in I rotated the device few times, and see the following information:

enter image description here

Here is MainActivity.class:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setFragment();

}
private void setFragment(){
    getSupportFragmentManager()
            .beginTransaction()
            .add(R.id.container, new MainFragment())
            .commit();
}
}

Here is how I log in to Facebook:

 public void configureFacebook(@NonNull Fragment fragment,
                              @Nullable String permissions, @Nullable String requestFields) {
    setPermissionAndRequestFields(permissions, requestFields);
    loginManager = LoginManager.getInstance();
    callbackManager = CallbackManager.Factory.create();
    loginManager.registerCallback(callbackManager, facebookCallback);
    loginManager.logInWithReadPermissions(fragment, Arrays.asList(this.permissions));
    loginManager=null;

}

I tried log in using Login Button too, in this case I catch this issue and new one, with following info:

enter image description here

Here is how I log in using LoginButton.class:

  public void configureFacebook(@NonNull Fragment fragment,
                              @Nullable String permissions, @Nullable String requestFields, @NonNull LoginButton button) {
    callbackManager = CallbackManager.Factory.create();
    setFbButton(button);
    setPermissionAndRequestFields(permissions, requestFields);
    fbButton.setFragment(fragment);
    fbButton.setReadPermissions(this.permissions);
    fbButton.registerCallback(callbackManager, facebookCallback);

}

I can't figure out how to fix those issues. What I am doing wrong?

UPDATE: Leak in Facebook Activity.class has been shown without the rotation device.

like image 205
Dennis Zinkovski Avatar asked Aug 21 '15 11:08

Dennis Zinkovski


People also ask

What is the main cause of memory leaks?

A memory leak starts when a program requests a chunk of memory from the operating system for itself and its data. As a program operates, it sometimes needs more memory and makes an additional request.

How did you avoid memory leaks?

To avoid memory leaks, memory allocated on heap should always be freed when no longer needed.

How serious are memory leaks?

Memory leaks may not be serious or even detectable by normal means. In modern operating systems, normal memory used by an application is released when the application terminates. This means that a memory leak in a program that only runs for a short time may not be noticed and is rarely serious.


2 Answers

Looks like they may have fixed this for Facebook SDK Version 4.2.0. see here

Updating the Facebook SDK may be the solution to your problem.

like image 87
Reid Mac Avatar answered Sep 30 '22 20:09

Reid Mac


I updated it to 4.7.0 and I think this issue has been fixed.

like image 43
Rohan Avatar answered Sep 30 '22 21:09

Rohan