1
votes

Retain counts are the way in which memory is managed in Objective-C. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain count is incremented by 1, which we know that ARC does it automatically but how it does what is the technique it use??

And I still wonder if memory management is done automatically then why sometimes we get bad access error for objects allocations or retrieval.

I have already gone through this link:- https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html

2
I really don't know why people down-vote?at least they must provide some reason or point out error or logical mistake in analysis of the question. There must be some validation before down-vote so that moderators can evaluate.Vizllx

2 Answers

2
votes

I think ARC (done by the compiler at compilation time, by inserting retain/release command where 'necessary') relies on the scope of variable, the block of code where they are defined (i.e. initialized) and if its value is stored in another variable whose scope is broader than the initial variable's scope.

That's why you have to declare more precisely the type of variable access and storage: to inform the compiler your intentions with a variable.

But I think too that ARC can't see further than the current file. ARC is more tricky with global variables and inter-files dependencies.

So, Apple a more complex variable's declaration grammar to replace a very simple (IMO) retain/release pattern. So developers don't have to worry about memory management.

That enable Apple ecosystem to be accessible to a lot more developers used to managed languages (like web developers) to develop for iOS.

I think it is a mistake to make developers believe you can develop efficiently without having to understand such a fundamental concept in IT as memory management.

But more developers for iOS means more programs developed and a more stable ecosystem in term of activity, so more revenues for Apple :-)

0
votes

You would be better off reading the ARC docs: https://developer.apple.com/library/ios/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html

ARC will manage the memory for you, but it cannot stop you from writing programming errors such as only holding weak references to an object.