I'm working on an app's user interface, and I'm doing it programmatically. I understand the idea behind retain cycles, and feel quite confident I could identify one, but Xcode is giving me warnings when I'm trying to avoid a retain cycle.

Essentially, I'm creating a property called `titleLabel` which will have my title, and in `viewDidLoad` I'm initializing it, and placing it on my view. The only problem is, I'm getting an Xcode warning that says:

> 
> Assigning retained object to weak variable; object will be released after assignment
> 
> 
> 

My property definition is as follows:

```
@property (nonatomic, weak) UILabel *titleLabel;

```

Obviously I could fix the Xcode warning by changing `weak` to `strong` in my property definition, but I believe that would create a retain cycle (from my understanding) because the button is holding onto the View Controller and the View Controller is holding onto the button.

Can anyone give me some insight as to how to do this properly?
['https://Stackoverflow.com/questions/33750465', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3411191/']
Your understanding is flawed. If the label were to retain a reference to its view controller, you would have a retain cycle if the property were defined as `strong`. However, views do not retain references to their view controllers, so there is no cycle. Xcode is warning you correctly that your label reference will go away after the assignment. You aren't even saved by adding it as a subview (which would retain it), because it's already released by the time you try.

The one quasi-exception to views not retaining references to controllers is with table and collection views, which have delegates and datasources which are usually their managing view controller. However, those delegate/datasource properties are defined as `assign` properties (which has another set of problems) so there is no retain cycle there, either.
i think you can set property to strong which will retain its memory and when your view will disappear call then you can set this object to nil which will release its memory.