Skip to content
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

Fix memory leak in [RecentsDataSource dataSource:didStateChange:] #4193

Merged
merged 1 commit into from
Oct 1, 2021

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Apr 8, 2021

The block passed into [MXSession listenToEventsOfTypes:onEvent:] is stored with a strong reference in the listenerBlock property of MXSessionEventListener. The method also returns the listener and it is then stored into the roomTagsListenerByUserId dictionary on self. Since a strong reference to self is captured in the block that means the block retains self (via the capture) and self retains the block (via roomTagsListenerByUserId) so there is a memory leak.

The bug is most easily reproduced during testing #4168 which involves closing the current and creating a new session.

Screenshot 2021-04-08 at 20 39 24

Signed-off-by: Johannes Marbach n0-0ne+github@mailbox.org

Pull Request Checklist

  • I read the contributing guide
  • UI change has been tested on both light and dark themes, in portrait and landscape orientations and on iPhone and iPad simulators
  • Pull request is based on the develop branch
  • Pull request updates CHANGES.rst
  • Pull request includes screenshots or videos of UI changes
  • Pull request includes a sign off

The block passed into `[MXSession listenToEventsOfTypes:onEvent:]` is stored with a strong
reference in the `listenerBlock` property of `MXSessionEventListener`. The method also
returns the listener and it is then stored into the `roomTagsListenerByUserId` dictionary
on `self`. Since a strong reference to `self` is captured in the block that means the block
retains `self` (via the capture) and `self` retains the block (via `roomTagsListenerByUserId`)
so there is a memory leak.

The bug is most easily reproduced during testing element-hq#4168 which involves closing the current
and creating a new session.

Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
@manuroe manuroe merged commit 5592fd4 into element-hq:develop Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants