Thanks
Thanks

Reputation: 40329

Why do I have to clean up memory if I have an IBOutlet with "retain", but not when I have one with "assign"?

Example:

@property (..., assign)

there, I don't do any cleanup in the dealloc Method. But when I have an

@property (..., retain)

then I would do so.

I have that from somewhere in the internet. Don't remember the site. Well, I know that the retain-keyword in the compiler directive would make a retain count +1, but actually I think that I missed the deep difference in assign and retain.

Upvotes: 0

Views: 103

Answers (1)

pgb
pgb

Reputation: 25001

Assign will only copy the pointer, and don't send a retain message to the object. Thus, since you are not retaining it, you don't have to release it.

In case of retain, as you say, it will send a retain message to the object, incrementing its retain count, so you are responsible of sending that object a release message when your object is (in your dealloc).

Upvotes: 2

Related Questions