1

I am creating an ipad app where I add many UIImageviews over other UIViews and UIImageviews. I am not sure whether to use strong or weak while adding UIImageviews as subviews . I have created a project without ARC and now I am looking forward to convert it to ARC(because of "easy memory management") but still not sure about how should I type(weak/strong) my views.

user1085093
  • 507
  • 1
  • 5
  • 9

1 Answers1

1

Are you really trying to add subviews to a view or to add reference to subviews in a view controller?

If your parent class is a subclass of UIView, you're really adding subviews to a view. So addSubview method add a strong reference to your view. You can use weak reference.

If your parent class is a subclass of UIViewController, you're not really adding subviews to a view. So nothing add strong reference to your object. Use a strong reference.

Mathieu Hausherr
  • 3,485
  • 23
  • 30
  • I have many UIImageviews in my app .I can classify them into 2 cases : Case 1: (strong /weak ?) Adding UIImageview as a subview to the view of the UIViewController(using [self.view addsubview(imageview)] Case 2: (strong /weak ?) Adding UIImageview as a subview to another UIImageview (which is added as a subview to self.view) – user1085093 Feb 28 '12 at 06:44
  • So you can just use weak references. addsubview add a strong reference to your view. – Mathieu Hausherr Feb 28 '12 at 13:05
  • So you mean to say declare UIImageviews as __weak and add them as subviews of the parent view. Are you suggesting this for both the cases – user1085093 Feb 28 '12 at 13:20