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
1
vote
2 answers

retain cycle without self?

I have a memory leak that seems to be coming from a retain cycle. The memory allocation size is increasing every time this code runs: - (void)nextPhoto { self.photoIndex++; if (self.photoIndex >= [self.photos count]) { …
Cbas
  • 6,003
  • 11
  • 56
  • 87
1
vote
3 answers

about __unsafe_unretained or__weak why can resolve retain cycle

//Parent.m #import "Parent.h" @implementation Parent{ dispatch_block_t _block; NSTimer *_timer; } - (instancetype)init { self = [super init]; if (self) { [self commonInitialization]; } return…
9527
  • 13
  • 3
1
vote
0 answers

my LogFunc macro captures self and might cause retain cycles

I use a simple macro in my code, I find it very convenient and useful #define LogFunc NSLog(@"%p %s",self,__func__); It gives me the self pointer address and the called function. @implementation MyGreatClass -(void)foo { LogFunc } -(void)bar…
Jakob
  • 1,126
  • 3
  • 16
  • 38
1
vote
2 answers

[SearchStockCell retain]: message sent to deallocated instance

I'm getting the following error: SearchStockCell retain]: message sent to deallocated instance 0x7f9fa1922c00 but I am having a hard time tracing the issue because whenever I profile with zombies, it stops without any warning or error(2-3 secs).…
shoujo_sm
  • 3,173
  • 4
  • 37
  • 60
1
vote
5 answers

How is a property related to "self" and vice-versa?

My question is two-part: First, Say I have a class: MyClass.h @interface MyClass: NSObject -(id)initWithName:(NSString*)name; @property(nonatomic, strong) NSString *name; @end MyClass.m @implementation…
1
vote
4 answers

The retain cycle with block

A question about the retain cycle with block. In the ARC Model. Say, an instance of view controller named 'vc', it holds reference to a block. Within the block, vc is used for some action : { //this is a piece of code snippet in vc …
itenyh
  • 1,921
  • 2
  • 23
  • 38
1
vote
2 answers

Sending removeFromSuperview to self didn't release itself in my scenario

I have a parent UIView and an UITextView as one of the subviews. And I created a button to dismiss the parent UIView like this: -(void)cancelButtonPressed:(UIButton *)sender { [UIView animateWithDuration:0.2 delay:0.0…
bolizhou
  • 1,208
  • 1
  • 13
  • 31
1
vote
1 answer

Similar way to override retain and release in Swift 1 or 2?

When things were really difficult, and I wanted to see why my retain count was so high, I'd just override retain/release and call super, set a breakpoint, and visually look at what is retaining my objects. I ran into a situation where this would…
Stephen J
  • 2,367
  • 2
  • 25
  • 31
1
vote
0 answers

Why no graph shows when I meet leak cycle in Xcode 6

I am trying to test the retain cycle in Xcode 6. I Write 2 class, one is TTChild and another is TTParent. The header file of them are as follows. @interface TTParent : NSObject @property (nonatomic,strong) NSMutableArray *children; @end @interface…
Jay
  • 113
  • 1
  • 11
1
vote
1 answer

Dealing with strong reference cycles in Xcode 6.4

Recently, I’ve received a quite large and ugly legacy code written in Swift 1.2 with full of singletones and managers referencing to each other. One of my task is to clean this up and get to the point of initial home screen - when all managers,…
1
vote
2 answers

Is this delegate property strongly referenced or not?

I have a problem in one of my VCs called ArticleViewController. The dealloc method is never called, and when the view is opened and closed three times, there are three VCs alive. I read here (great source when you have a retain cycle in your…
1
vote
1 answer

Retain loop in a block

I'm trying to get variables and properties in self in a block for actions to complete, but, if I reference self or a global variable in self when self is the object running the block, it warns me of a retain loop. Here's what I'm doing: I'm adding…
DDPWNAGE
  • 1,423
  • 10
  • 37
1
vote
2 answers

retain cycle with target-selector

I am new to retain cycle which I am confused if my situation falls into. I have a singleton class Singleton.h @interface Singleton : NSObject + (Singleton *)sharedInstance; - (void)doSomethingWithData:(NSDictionary *)data…
quanguyen
  • 1,443
  • 3
  • 17
  • 29
1
vote
2 answers

why retain of delegate is wrong what are all alternatives...?

I have one problem let assume A and B are 2 view controller from A user push to B view controller,In B user starts some download by creating object C(which is NSObject class) and sets B as delegate to C(assign),now user want go back to A then…
jeeva
1
vote
3 answers

Do methods called from within a block need to use weakSelf?

If the code inside a block calls a method, will a retain cycle exist if that method references self? In other words, does all code downstream of a block need to use the weakSelf/strongSelf pattern? For example: __weak __typeof__(self) weakSelf =…
smeep
  • 332
  • 1
  • 17