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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(banner, ios): fixed memory leak #565

Merged
merged 2 commits into from May 2, 2024
Merged

Conversation

birdofpreyru
Copy link
Contributor

Description

Related issues

#496

Release Summary

  • Fixes memory leak when using banners on iOS with old RN architecture.

Checklist

  • I read the Contributor Guide
    and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
  • My change includes tests;
    • e2e tests added or updated in __tests__e2e__
    • jest tests added or updated in __tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan


Think react-native-google-mobile-ads is great? Please consider supporting the project with any of the below:

  • 馃憠 Star this repo on GitHub 猸愶笍
  • 馃憠 Follow Invertase on Twitter

@dylancom
Copy link
Collaborator

dylancom commented Apr 26, 2024

Thanks for the investigation and PR.
I also pushed a fix for banners in the new arch.

_banner.paidEventHandler = ^(GADAdValue *_Nonnull value) {
[self sendEvent:@"onPaid"
[weakSelf sendEvent:@"onPaid"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The weak reference should be unwrapped. To avoid crashes if self could have been deallocated by the time the block executes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  __weak typeof(self) weakSelf = self;
  _banner.paidEventHandler = ^(GADAdValue *_Nonnull value) {
    typeof(self) strongSelf = weakSelf;
    if (strongSelf) {
      [strongSelf sendEvent:@"onPaid"
                    payload:@{
                      @"value" : value.value,
                      @"precision" : @(value.precision),
                      @"currency" : value.currencyCode,
                    }];
    }
  };

_banner.paidEventHandler = ^(GADAdValue *_Nonnull value) {
[self sendEvent:@"onPaid"
[weakSelf sendEvent:@"onPaid"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  __weak typeof(self) weakSelf = self;
  _banner.paidEventHandler = ^(GADAdValue *_Nonnull value) {
    typeof(self) strongSelf = weakSelf;
    if (strongSelf) {
      [strongSelf sendEvent:@"onPaid"
                    payload:@{
                      @"value" : value.value,
                      @"precision" : @(value.precision),
                      @"currency" : value.currencyCode,
                    }];
    }
  };

@dylancom dylancom merged commit 5cbf0e9 into invertase:main May 2, 2024
7 of 10 checks passed
@mikehardy
Copy link
Collaborator

馃帀 This PR is included in version 13.2.1 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants