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
0
votes
1 answer
Retain cycle in AFNetworking success block
Usually, Xcode shows a warning when using a strong reference in a block (retain cycle). However, I don't understand why it doesn't show it with this AFNetworking example.
UIImageView *imageView;
AFHTTPRequestOperation *operation = [apiQueryManager…

Noé Malzieu
- 2,530
- 3
- 22
- 27
0
votes
1 answer
Am I using this block correctly?
Question: Am I using this block correctly? No leaks or retain cycles?
Question 1.5: Is this good style or should I just do an inline block?
typedef void(^completionBlock)(void);
...
-(completionBlock)completionBlock{
return ^{
…

Emin Israfil iOS
- 1,801
- 1
- 17
- 26
0
votes
2 answers
iOS: Simple Retain Cycle
Let's say you have have a viewController with:
@property (strong) object* A
@property (strong) object* B
You then purposely create a retain cycle at somepoint, without timers, such that
self.A.someStrongProperty = self //retain cycle
Question:…

Emin Israfil iOS
- 1,801
- 1
- 17
- 26
0
votes
2 answers
Block capturing 'self' strongly
I have the following action for a button, which toggles whether an object is shown as favorite or non-favorite:
- (IBAction)addToFavorites:(UIButton *)sender {
if ([object isFavorite]) {
[_apiManager removeFromFavorite:[object ID]…

Guilherme
- 7,839
- 9
- 56
- 99
0
votes
1 answer
Accessing self inside GCD block in iOS
When I access a self object inside a view animation API like this
[UIView animateWithDuration:10 animations:{
// accessing self object.
}];
will this lead to retain cycle?
Thanks

Naveen
- 636
- 8
- 28
0
votes
1 answer
retain cycle inside of block with local scope ivars
For the life of me, I cannot figure out what's going on here.
As an overview, I have an application that I've created a custom navigation bar, a custom containment view controller, and callbacks to tell me when expensive processes have been finished…

dannyskim
- 165
- 2
- 8
0
votes
1 answer
iOS - Call method in one childViewController when a property value is changed in another
I have two childViewControllers of the same parent, say methodChild and propertyChild, and want a method in methodChild to be called every time a new value is set in one of propertyChild's properties. What is a good way to do this?
One solution…

Rogare
- 3,234
- 3
- 27
- 50
0
votes
1 answer
Apple decumentation on objects in blocks
Apple documentation on this matter states:
When a block is copied, it creates strong references to object
variables used within the block. If you use a block within the
implementation of a method:
If you access an instance variable by…

MegaManX
- 8,766
- 12
- 51
- 83
0
votes
1 answer
Am I creating a retain cycle between UIViewController and a custom object?
In a project using ARC, I have a UIViewController that is handling too many concerns, so I'm looking to split things up. One obvious thing for me to take out is a method that formats and sends an email, and split that into a separate object.
My…

Mattio
- 2,014
- 3
- 24
- 37
0
votes
1 answer
Blocks are blocking my view
suppose I do this:
MyClass *vista = [[MyClass alloc] initWithFrame:CGRectZero];
vista.onFinish = ^{
CGRect rect = vista.bounds;
// bla bla bla
};
then xcode will award me with this error: capturing vista strongly in this block is likely to…

Duck
- 34,902
- 47
- 248
- 470
0
votes
2 answers
Objective-C / Blocks - Isn't this a retain cycle?
@interface ClassA : NSObject
@property (strong, nonatomic) dispatch_queue_t dispatchQ;
@property (strong, nonatomic) NSString *string;
@end
@implementation ClassA
- (id)init
{
self = [super init];
if (self) {
_dispatchQ =…

edelaney05
- 6,822
- 6
- 41
- 65
0
votes
1 answer
Leaderboard Requests, Nested Blocks, and Retain Cycles
I have developed a leaderboard display class for my iPhone game. The class has the following instance method.
-(void)displayScoresWithRequest:(CBLeaderboard*)request completionHandler:(void(^)())completionHandler
{
if (request_ != nil)
…

Sam Hertz
- 161
- 9
0
votes
2 answers
iOS Blocks. How do I refer to the object instance from within a block setter?
I have an object with a property that points to a block:
typedef void (^ThingSetter)();
@property(nonatomic, strong) ThingSetter setup;
I initialize the property with a block. Within the block I refer to the object instance:
Thing *thing = [[Thing…

dugla
- 12,774
- 26
- 88
- 136
0
votes
1 answer
Retain cycle possibility when calling a getter on a weak pointer and passing it to a method
I've been reading up more on retain cycles all day and I'm starting to confuse myself. So I just wanted to check a couple of things. (Just for clarification, I'm using ARC)
So let's say I have MyFirstClass. MyFirstClass has an strongly pointed (by…

Dom Chapman
- 953
- 2
- 10
- 15
0
votes
1 answer
Is it bad to set two Views in a SplitView to hold a reference to each other?
I'm currently writing an RSS program in which my splitViewController's views have to talk to each other. Both of them currently hold a propertied instance of each other which is declared in the App Delegate as mentioned below. I want to know if this…

TheCodingArt
- 3,436
- 4
- 30
- 53