Questions tagged [retain-cycle]

A retain cycle is a situation in reference-counted memory management when two (or sometimes more) objects have strong references to each other. Normally, objects are destroyed when their reference count reaches zero, and the references they hold are released at that time. In a cycle, each object keeps the other alive, and neither will be destroyed unless the cycle is deliberately broken.

301 questions
0
votes
0 answers

Why does Injecting a Binding into UIViewControllerRepresentable cause a retain cycle?

So there seems to be a retain cycle when injecting a Binding that is a published property from an ObservableObject into UIViewControllerRepresentable. It seems if you create a view inside another view in and that second view has an ObservableObject…
0
votes
1 answer

Swift How to return child object that keeps parent object as long as child lives in memory

I consider whether it is possible to return from function child object created inside parent object that will keep reference to its parent and prevent parent from being deallocated from memory. Simultaneously I don't want to have retain cycle and…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
0
votes
2 answers

Cell isn't being deallocated after table view is dismissed, being referenced by closure's context

I'm creating a custom table view cell, which allows the user to add, take, or view uploaded photos. I discovered that this cell stays in memory forever even after the table view's dismissal, creating weird memory graph. I want the cell to be…
0
votes
1 answer

Should I check the existence of weakself before use @strongify(self) in ReactiveObjc?

As the other practice in weak and strong, it recommends that we should check whether the weakself is null before we strongify it. It looks like this: __weak weakself = self someblock { if (weakself) { __strong self = weakself [self…
0
votes
1 answer

Back button not being called in TabbarCoordinator in horizontal flow iOS 12

Coordinator pattern is an old topic with many libraries trying to solve it and I am learning it in simple example app. My current set up is 3 rootViewControlers: LoadingStateCoordinator, WelcomeCoordinator, TabBarCoordinator but missing connection…
0
votes
0 answers

Prevent retain cycle in Swift

I have the following class in my project, I am wondering if this implementation will end up doing retain cycle public final class CalendarService: AccessTokenProvider { internal var accessToken: Observable = ... private let…
Bobj-C
  • 5,276
  • 9
  • 47
  • 83
0
votes
1 answer

Why Swift don't automatically handle memory leaks?

When I started developing Swift code I wasn't that experienced handling memory leaks, so it take some time to me to figure out that what is a retain cycle, what is ARC, and why I should use weak or unowned inside my closures that was creating those…
chr0x
  • 1,151
  • 3
  • 15
  • 25
0
votes
0 answers

Why is `self` is not required in first closure?

1) I cannot understand why is self not required in first closure. Usually you get a compile-time error that goes something like this: "add self to make capture semantics explicit". myCollectionView is an IBOutlet and myItems is a property, they are…
realvadim
  • 154
  • 12
0
votes
2 answers

Do I need to capture self weakly inside a UIAlertController's action completion handler

I've read that self doesn't need to be captured weakly in a UIAlertController action completion handler if the UIAlertController reference is weak. The reason being that UIAlertController is designed to release everything once it's done executing,…
alexisSchreier
  • 677
  • 1
  • 5
  • 21
0
votes
1 answer

ViewController in navigation stack won't deinit when popped, causing memory leak

In my app I have a RootViewController which all my ViewControllers are subclassed from. When developing, I usually use this in my RootVC: deinit { print("\(type(of: self)) deinit") } so that I always can see when any of my viewControllers…
Sti
  • 8,275
  • 9
  • 62
  • 124
0
votes
0 answers

Swift 4 retain cycle different from swift 3?

I incurred a small problem to solve retain cycle in Swift 4. (the same code works fine in swift 3) what do i miss please? class User { weak var device:Device? init() { print("User allocated") } deinit { print("User…
Rebecca
  • 653
  • 6
  • 14
0
votes
1 answer

Adding a collectionview to a collection view cell leads to memory growing

Ive created a CollectionView called and on each CollectionViewCell I have created a CollectionView. Below I have included the code for the collectionView which goes inside the cell of the MainCollectionView. Every time that I swipe through the cells…
0
votes
0 answers

I seem to have a retain cycle with a weak delegate

I'm using a networker inside of a view controller. The networker has a weak delegate reference to the view controller. After a view controller is dismissed I kick off a timer to check whether the vc has been released. I noticed that it's not being…
MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
0
votes
1 answer

Will this code produce retain cycle ? (Core Data perform)

extension NSManagedObject{ /// Perform on main context asynchrounously /// SaveContext will be called after the block() is executed /// - Parameter block: The blcok of code passing context as param class func…
infiniteLoop
  • 2,135
  • 1
  • 25
  • 29
0
votes
1 answer

Dismiss rootViewController on UIApplicationWillTerminate

When trying to dismiss root view controller; This code works in other functions but not in a function which is get called by UIApplicationWillTerminate notification. let appDel = UIApplication.shared.delegate as! AppDelegate …