Skip to content

Commit

Permalink
- bug fix memory leak
Browse files Browse the repository at this point in the history
- add sanity check to ensure we are tracking address changes before we start the staking wizard
  • Loading branch information
simonmcl committed Jan 10, 2025
1 parent a4b7937 commit bd9c981
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Account/AccountViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class AccountViewController: UIViewController, UITableViewDelegate, EstimatedTot
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.isPresentedForSelectingToken = (self.parent != nil && self.tabBarController == nil)
Expand Down
4 changes: 4 additions & 0 deletions Kukai Mobile/Modules/Account/AccountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class AccountViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Account/TokenDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class TokenDetailsViewController: UIViewController, UITableViewDelegate {
}
}

deinit {
cancellable = nil
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

Expand Down
6 changes: 6 additions & 0 deletions Kukai Mobile/Modules/Account/TokenDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ public class TokenDetailsViewModel: ViewModel, TokenDetailsChartCellDelegate {
}.store(in: &bag)
}

// deinit doesn't reliably call, even when the parent VC does call deinit.
// add backup for now until more testing can be done
deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Activity/ActivityViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class ActivityViewController: UIViewController, UITableViewDelegate {
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
viewModel.isVisible = true

Expand Down
4 changes: 4 additions & 0 deletions Kukai Mobile/Modules/Activity/ActivityViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class ActivityViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class CollectiblesCollectionsViewController: UIViewController, UICollectionViewD
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.isVisible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class CollectiblesCollectionsViewModel: ViewModel, UICollectionViewDiffableDataS
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class CollectiblesFavouritesViewController: UIViewController, UICollectionViewDe
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.isVisible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class CollectiblesFavouritesViewModel: ViewModel, UICollectionViewDiffableDataSo
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class CollectiblesRecentsViewController: UIViewController, UICollectionViewDeleg
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.isVisible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class CollectiblesRecentsViewModel: ViewModel, UICollectionViewDiffableDataSourc
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class CollectionDetailsViewController: UIViewController, UICollectionViewDelegat
}
}

deinit {
cancellable?.cancel()
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.isVisible = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class CollectionDetailsViewModel: ViewModel, UICollectionViewDiffableDataSourceH
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Discover/DiscoverViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class DiscoverViewController: UIViewController, UITableViewDelegate, DiscoverFea
}.store(in: &bag)
}

deinit {
bag.forEach({ $0.cancel() })
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.isVisible = true
Expand Down
4 changes: 4 additions & 0 deletions Kukai Mobile/Modules/Discover/DiscoverViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class DiscoverViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Home/AccountsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class AccountsViewController: UIViewController, BottomSheetContainerDelegate {
}
}

deinit {
cancellable = nil
viewModel.cleanup()
}

func bottomSheetDataChanged() {
viewModel.isPresentingForConnectedApps = (bottomSheetContainer != nil)
viewModel.addressToMarkAsSelected = addressToMarkAsSelected
Expand Down
4 changes: 4 additions & 0 deletions Kukai Mobile/Modules/Home/AccountsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class AccountsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Stake/BakerDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class BakerDetailsViewController: UIViewController {
}
}

deinit {
cancellable?.cancel()
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

Expand Down
4 changes: 4 additions & 0 deletions Kukai Mobile/Modules/Stake/BakerDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class BakerDetailsViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
5 changes: 5 additions & 0 deletions Kukai Mobile/Modules/Stake/ChooseBakerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class ChooseBakerViewController: UIViewController {
}
}

deinit {
cancellable?.cancel()
viewModel.cleanup()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

Expand Down
4 changes: 4 additions & 0 deletions Kukai Mobile/Modules/Stake/ChooseBakerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class ChooseBakerViewModel: ViewModel, UITableViewDiffableDataSourceHandler {
}

deinit {
cleanup()
}

func cleanup() {
bag.forEach({ $0.cancel() })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ class StakeOnboardingContainerViewController: UIViewController {
indicatorStackviewTrailingConstraint.constant = 24 * 5
}

// triple make sure activity listener is up and running before we start
AccountViewModel.setupAccountActivityListener()

// Listen for requests to add pending operations
DependencyManager.shared.activityService.$addressesWithPendingOperation
.dropFirst()
.sink { [weak self] addresses in
Expand Down

0 comments on commit bd9c981

Please sign in to comment.