Skip to content

Memory Leak from Unremoved Click Listeners in onCreateView #279

@Mehrad25Software

Description

@Mehrad25Software

Method: onCreateView() in BottomSheetMenuFragment.java

Description:
Click listeners registered in onCreateView() are not properly removed in onDestroyView(), causing memory leaks when the fragment is recreated multiple times.

Steps to Reproduce:

  1. Open the bottom sheet menu multiple times
  2. Close and reopen the fragment repeatedly
  3. Monitor memory usage (increases over time)

Expected Behavior:
Listeners should be cleaned up when fragment is destroyed to prevent memory leaks.

Actual Behavior:
Listeners remain in memory, causing gradual memory accumulation and potential OutOfMemory errors.

Proposed Fix
Clear click listeners before nullifying the binding in onDestroyView():

@Override
public void onDestroyView() {
    super.onDestroyView();
    if (binding != null) {
        binding.menuSettings.setOnClickListener(null);
        binding.menuHelpFeedback.setOnClickListener(null);
        binding.menuUpdates.setOnClickListener(null);
        binding.menuShare.setOnClickListener(null);
        binding = null;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions