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

BasePurchasesTests: fixed leak detection #2534

Merged
merged 2 commits into from
May 24, 2023
Merged

BasePurchasesTests: fixed leak detection #2534

merged 2 commits into from
May 24, 2023

Commits on May 23, 2023

  1. BasePurchasesTests: fixed leak detection

    While working on #2533, I knew that my proof of concept had a retain cycle. I however was very confused when it wasn't detected by this mechanism introduced first introduced in #2104.
    
    Turns out that this had been wrong the whole time: the current implementation, as explained by the comment, was executing those blocks in LIFO order, which meant that the references were being set to `nil` before the assertions could be created.
    This meant that by the time the `except { [weak purchases = self.purchases] ... }` lines were called, `self.purchases` itself was `nil`, so nothing was being checked.
    
    This simplifies the implementation by inlining the checks, and saving a `weak` reference before clearing the singleton and all the local references.
    
    Luckily there was only one failing test that had to do with how `Purchases` was being created, and implementation details of `expectFatalError`. To avoid this, I changed the test to use the `Purchases.init` method directly.
    NachoSoto committed May 23, 2023
    Configuration menu
    Copy the full SHA
    9145392 View commit details
    Browse the repository at this point in the history
  2. Extracted method

    NachoSoto committed May 23, 2023
    Configuration menu
    Copy the full SHA
    6954eff View commit details
    Browse the repository at this point in the history