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
2
votes
0 answers

UIStoryboardSegue has retain-cycle with its destinationViewController

I'm driving a UIStoryboardSegue with a UIPercentDrivenInteractiveTransition that is based on a user gesture. If the gesture ends before it has reached a certain completion rate, the segue is canceled by calling cancelInteractiveTransition on the…
Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
2
votes
1 answer

Using 'self' on RxSwift closures... What about instance methods as param?

In other stack overflow questions, it was emphasized that the capture [weak self] should be used for closures that aren't owned by the class because self could be nil before the closure completes. An alternative when the closure is owned by the…
dsapalo
  • 1,819
  • 2
  • 19
  • 37
2
votes
1 answer

How to pass a function as parameter avoiding retain cycles?

I have a view controller where I am trying to call Timer.scheduledTimer(withTimeInterval:repeats:block) by passing a function as block parameter, instead of creating a block on the fly. I have this view controller: class ViewController:…
manueGE
  • 1,169
  • 11
  • 14
2
votes
1 answer

Two ways of block for preventing retain-cycle

I usually use block like this if there might be a retain-cycle: - (void)someFunction { __weak __typeof(self) weakSelf = self; [self setHandler:^{ [weakSelf doSomething]; }]; } But recently I saw another way like: -…
Klein Mioke
  • 1,261
  • 2
  • 14
  • 23
2
votes
1 answer

No Retain Cycle, But why still got retain cycle warning?

I am trying to use UIImageView extension of AFNetworking2.6.3 to get images from a remote server. everything works fine, images have returned and rendered successfully. but I get a retain cycle warning in Xcode7.3.1: Capturing 'cell' strongly in…
Lyn
  • 29
  • 2
2
votes
1 answer

iOS - Weak var can still cause retain cycle?

Here is my real code: @IBOutlet weak var contentTextView: SmartTextView! { didSet { self.contentTextView.onDidBeginEditing = { $0.layer.borderColor = Util.green.CGColor } self.contentTextView.onDidEndEditing…
YON
  • 1,607
  • 3
  • 18
  • 33
2
votes
2 answers

iOS Memory management, (leaks, retain cycles)

I have some general questions about what happens to app memory. What happens to memory when the app enters the background or suspended. I'm asking this because my app has some memory leaks that are, from my research, bugs in Apple's framework and…
B Wu.
  • 83
  • 7
2
votes
1 answer

SpriteKit Retain Cycle Or Memory Leak

My SpriteKit game has three scenes for now; Menu.m, LevelSelect.m and Level.m. When I start the app, the memory usage is 35MB. Upon transitioning from the main menu to the level selection scene it pretty much stays around 35MB. Moving from the level…
02fentym
  • 1,762
  • 2
  • 16
  • 29
2
votes
2 answers

Retain cycle in Swift when Object A has Object B as a property and Object B has an array property that contains Object A?

Confused about a situation that might be a retain cycle? I understand that if class Object-A { var b: Object-B } and class Object-B { var a: Object-A ] then above is horrible design because if you do var a = Object-A() var b =…
Terry Bu
  • 889
  • 1
  • 14
  • 31
2
votes
2 answers

Different closures giving different results for retain cycles in swift

I am reading Apple's Swift Programming Language Guide. In the part about Strong Reference Cycle for closures, I tried a different type of closure but it did not give the expected output. class HTMLElement { let name: String let text: String? lazy…
2
votes
2 answers

Objective C - Lost with retain cycles

upon dismissing my VC, I noticed I am not releasing everything from memory. I'm very lost as to how I would go about finding my retain cycle. I am using an NSTimer and NSNotificationCenter, but I make sure to invalidate and removeObservers before…
Andy
  • 750
  • 7
  • 23
2
votes
1 answer

runblock retain self reference cause memory dealloc issue

Here is my code: ship.runAction(SKAction.waitForDuration(5), completion: { self.ship.flyStraight()//retain self }) After several days googling for the memory issues, finally I found that I had a self retain in this block. When I create the new…
Alfred
  • 161
  • 10
2
votes
4 answers

Do I need to use a weak self pointer if a method called from a Block uses self?

Using self. in blocks causes retain cycles, so I need to create a reference to weakSelf. I understand this BUT! If from my block I call a method which uses self", does this too cause a retain cycle? For instance, if I reload a UITableView from a…
MobileMon
  • 8,341
  • 5
  • 56
  • 75
2
votes
1 answer

Using method with self inside blocks

I need to execute same bunch of code in two blocks (I'm using ARC): __weak typeof(self) weakSelf = self; [_dataProvider doA:^(NSError *error) { [weakSelf handleError:error]; }]; And in a different place i call: __weak typeof(self) weakSelf =…
Nat
  • 12,032
  • 9
  • 56
  • 103
2
votes
1 answer

iOS: Blocks and ivars

In a lot of question it is asked if its ok to use self in blocks. The answer is no, to avoid retain cycle. Now when i use an "ivar" in my block in my UIViewController it should be fine. But when i use: - (void)viewDidLoad { [_customCell…
Oritm
  • 2,113
  • 2
  • 25
  • 40