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.
Questions tagged [retain-cycle]
301 questions
1
vote
1 answer
__weak SLComposeViewController cause crash in IOS 8
I have a problem with SLComposeViewController in IOS 8. I want to show Facebook sharing window and after it's done - show Twitter sharing window. That's why I need to use completion blocks and to avoid retain cycles I have to use __weak…

POF_Andrew_POF
- 103
- 7
1
vote
1 answer
Function stored as variable can cause reference cycle?
If I have a class, that stores an others class function as a variable, can that cause reference cycle?
For example
class ClassA {
var i = 0
func incrementI() {
i++
}
}
class ClassB {
private var function: () -> ()
…

Dániel Nagy
- 11,815
- 9
- 50
- 58
1
vote
1 answer
Strongly in this block is likely to lead to a retain cycle
I create the custom cell with the activity indicator view
With using the SDWebImage I hidden the activity indicator when the image is downloaded
[customCell.userPhotoImageView setImageWithURL:[NSURL URLWithString:[[thisNotify user]imageURL]]…
user1784067
1
vote
2 answers
weak variable with a strong reference in a block: does not create a retain cycle?
why does it work when we pass the weak reference to a strong reference inside the block? If a local variable in a block is retained, this should add a retain to self and thus create this bad retain cycle?
Here is the example :
__weak id weakSelf =…

Paul
- 6,108
- 14
- 72
- 128
1
vote
1 answer
Does retainership really matter when dealing with Swift objects & arrays?
For the purpose of this question, let us say that I have a class that represents any given type of data. The objects of these classes can "connect" to one another in order to form a network.
class DataObject
{
var value: Any?
var…

Vatsal Manot
- 17,695
- 9
- 44
- 80
1
vote
1 answer
Retain Cycle Even when using Weak/Strong ARC Semantics
`I admit that I am not an expert on ARC and retain cycles though through some research and some great articles (like this), I believe I get the basics.
However, I am currently stumped. I have a property defined as follows.
@property…

Ternary
- 2,401
- 3
- 31
- 54
1
vote
1 answer
Will this cause a retain cycle? (obj-c, sample code)
SomeViewController *newController = [SomeViewController new];
[newController setSomeBlock:^{
[self.someProperty doSomething];
}];
[self presentViewController:newController animated:YES completion:nil];
SomeViewController has someBlock as a…

Jiho Kang
- 2,482
- 1
- 28
- 38
1
vote
2 answers
why it is recommended to use the _weak reference with delegates
Hi every one whether some one will elaborate me that why it is recommended to use the _weak reference for delegates and not the strong reference? though we can also use the strong reference for delegates. Some one will please tell me with the better…

iShwar
- 1,625
- 1
- 16
- 31
1
vote
2 answers
How to break Core Data mult-threading retain cycles on merging changes?
In my application I'm using CoreData for storage and displaying data using NSFetchedResultsController.
I followed tutorials from raywenderlich to get it done and it's a lot of code - but it's working properly in general - will post parts of it when…

Grzegorz Krukowski
- 18,081
- 5
- 50
- 71
1
vote
2 answers
iOS - dispatch_async retain cycle with CoreData
I am new to dispatch_queue's and have ran into a problem trying to save to CoreData in the background. I have read the CoreData programming guide and I am creating a separate NSManagedObjectContext while in the background thread. When I do a simple…

kev
- 2,306
- 3
- 26
- 31
1
vote
1 answer
Will This CAAnimation Cause a Leak or Retain Cycle?
Question: If the ViewController containing the UIView to which the animation below was applied to was deallocated, would it cause a memory leak or retain cycle?
In other words, if I applied this animation to a uiview, would it cause a memory leak or…

Emin Israfil iOS
- 1,801
- 1
- 17
- 26
1
vote
1 answer
Understanding this Xcode 4.6 Allocations Instruments Output: Retain Cycle Detection
I think I'm getting a retain cycle. It happens as I push and dismiss a VC.
Every time I push and dismiss, similar objects build up.
Can someone help me understand this profiler output. (photo above)
Question 1 + 1.5: It seems like an event…

Emin Israfil iOS
- 1,801
- 1
- 17
- 26
1
vote
2 answers
Possible Retain Cycle -- iOS/Objective - C
I am parsing data from a XML file and believe I've found a retain cycle. I don't have the best understanding how to fix it though. In short, I'm parsing out a bunch of floats within a block which leads to my memory usage going through the roof - it…

kschins
- 1,054
- 1
- 13
- 26
1
vote
3 answers
Why the retain cycle warning not thrown?
I use Xcode 5 and have some code
@interface Controller {
__weak IBOutlet UIView *someView;
}
@implementation Controller {
- (void)doSomething
{
[UIView animateWithDuration:0.5 animations:^{
someView.hidden = YES;
}];
}
-…

efpies
- 3,625
- 6
- 34
- 45
1
vote
1 answer
Retain cycle with AFNetworking
I'm writing a gallery with images which can be loaded by url with AFNetworking.
In Init method of the ImageView object I call a function that send a request. Here:
- (void) loadWithUrl:(NSURL *)url
{
NSMutableURLRequest *request =…

Mike
- 481
- 10
- 24