Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • __weak and __unsafe_retained

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 667
    Comment on it

    __weak and __unsafe_unretained are the ownership qualifiers introduced by LLVM Compiler 3.0.

    By default all pointers are __strong under ARC which means that when an object is assigned to a pointer, it is retained for as long as that pointer refers to it. This causes the retain cycles.
    Lets say you have two objects one contains another as an instance variable and second object has strong link to first one. then this will cause retain cycle and both objects will never be released.

    Their most common use can be find while using delegate where one defines the property of a delegate with "__weak" or "__unsafe_unretained". This means that the delegate instance variable will still point back at the first object, but it will not cause that object to be retained, thus breaking the retain cycle and allowing both objects to be released.

    We can declare any object 'weak' or 'unsafe unretained' by using keyword '__weak' and '__unsafe_unretained'. These are very useful to break any retain cycle. the above release can be done using __weak or __unsafe_unretained.

    Note* '__weak' is only supported for iOS 5.0 and Lion as deployment targets.
    If you want to target back to iOS 4.0 and Snow Leopard, you have to use the '__unsafe_unretained'.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: