Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iVars references strong, weak or what?

In Obj-C, properties can be configured to be weak/strong. Instance variables. like following -

@interface MyClass {
NSObject *a;
}

Does the MyClass's object keep weak reference to a or strong, or something else? I think iVar is not released until its object is released. Why don't we specify weak/strong for iVar like properties?

like image 683
user1559227 Avatar asked May 09 '13 12:05

user1559227


People also ask

What is the difference between strong and weak references?

The key difference between a strong and a weak or unowned reference is that a strong reference prevents the class instance it points to from being deallocated. That is very important to understand and remember. ARC keeps track of the number of strong references to a class instance.

What is strong reference and weak reference in Objective C?

There are two types of object reference: Strong references, which keep an object “alive” in memory. Weak references, which have no effect on the lifetime of a referenced object.

What is weak and strong in Swift?

For example, a strong reference keeps a firm hold on instances and doesn't allow deallocation by ARC. Similarly, a weak reference cannot protect the instances from being deallocated by ARC. Before you learn about strong and weak reference, make sure to understand how classes and objects work in Swift.

What is weak reference in Objective C?

Pointers that are not retained are often referred to as “weak” in Objective-C documentation that predates the garbage collector. These are references that are allowed to persist beyond the lifetime of the object. Unfortunately, there is no automatic way of telling whether they are still valid.


1 Answers

the default reference to ivar is __strong, though you can explicitly set it to be __weak or __strong


like image 54
kap Avatar answered Oct 14 '22 09:10

kap