cocoa - What is difference between retain and strong in objective-c? -


this question has answer here:

looking forward response other : - arc , non-arc environment

strong , weak retain-release cycles (rrc), form of memory leak. ios uses called automatic reference countin (arc) know when object in use , should kept in memory, or no longer in use , should deleted gain resources. arc works because runtime knows each object, how many objects referencing it. when found reaches 0, object deleted.

issues arise when have 2 objects hold references each other. because object holds reference object b, , b a, reference count both , b never 0, , b in memory. it's possible there no other objects holding references or b, we've created memory leak.

getting strong , weak, these keywords used "denote ownership", if will. eliminate retain-release cycles limiting objects increment reference count object. strong property 1 increment reference count of object. if object has strong reference b, , no other object referencing b, b has count 1 (a owns, or needs exist b). now, if b wants have reference a, want use weak reference. weak references don't increment reference count of object. in particular case, if has no other objects referencing b, a's count 0 given b's weak reference.

can see how eliminating rrc? assuming no external references , not using strong/weak references, , b perpetually reside in memory. using strong , weak references outlined above, have count 0, removed memory. in turn deincrement b's reference count 1 0, causing b removed memory.

nonatomic used denote object being referenced in not thread safe. means object not able deal multiple requests @ same time. atomicity idea once make request, either happens or doesn't. when operation atomic, you're guaranteeing entity you're applying operation never in intermediate state. regardless of how @ entity, either looks way did before requested operation, or looks way once operation done. (when thinking atomicity, think of atoms. word means indivisible. atomic operations can't divided smaller operations.)


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -