Do I need to release xib resources?

后端 未结 8 962
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-04 08:40

If I have something like a UILabel linked to a xib file, do I need to release it on dealloc of my view? The reason I ask is because I don\'t alloc it, which makes me think I

相关标签:
8条回答
  • 2020-12-04 09:26

    You do alloc the label, in a sense, by creating it in IB.

    What IB does, is look at your IBOutlets and how they are defined. If you have a class variable that IB is to assign a reference to some object, IB will send a retain message to that object for you.

    If you are using properties, IB will make use of the property you have to set the value and not explicitly retain the value. Thus you would normally mark IBOutlet properties as retain:

    @property (nonatomic, retain) UILabel *lblExample;
    

    Thus in ether case (using properties or not) you should call release in your dealloc.

    0 讨论(0)
  • 2020-12-04 09:28

    Related: Understanding reference counting with Cocoa / Objective C

    0 讨论(0)
提交回复
热议问题