Posted By Our Mentors
Amreen Khan
Android Developer
animesh bansal
iphone App Developer
Devendra chouksey
Android Developer
Dilip Saket
IOS apps developer
Hemraj Jhariya
iOS Developer
Jaihind singh Rajput
Smart Phone App Dev
Mujahid khan
Android developer
Narendra Yadav
android developer
Narinder Gupta
Mobile App Architect
Pradeep singh Thakur
Mobile App Architect
Sanjay Sharma
Andriod Developer
Shakti Rajpal
IT Architect
Soniya Vishwakarma
iPhone App Developer
Sunil Raghuwanshi
iPhone App Developer
Supriya Kapse
Senior developer
Programmer's Role In Automatic Reference Counting (ARC) Iphone/iPad
ARC stands for Automatic Reference Counting walked out via apple in the year 2011 to enable a great programmers ease with their development procedures. With ARC, a developer can handle the entire memory of IOS application quite accurately.
Posted By: Dilip Saket Date: 21 Dec 2013 View: 2130
      Rate This !!


Automatic Reference Counting (ARC) is a memory management technique to manage the memory in IOS Application. ARC is a compiler's feature to manage the memory. Apple delivered a fully featured version of ARC in 2011 with IOS 5 for application development.

In earlier days while developing an IOS app we always have a headache to manage the memory in our application. If we don't manage memory than our app will crash randomly while using the app and the application will perform very slowly.

While handling the memory in IOS, we use retain, release, alloc, and autorelease methods. In IOS NSObject has a integer called retainCount the value of this integer is zero or a positive. Zero value of retainCount shows that the object is free now to release the memory. To decrease the retainCount of an object we call release method, this method decrease the retainCount by one and the value of retainCount increases when we call retain methods it just increase the retainCount by one. When we call alloc it creates memory for the object and set retainCount value to one,

If developer is not using ARC in his application So it is the developer's responsibility to manage memory. And if developer is using ARC in his application code than memory management shifts from developer to the compiler, ARC is responsible to decrease the retainCount of an object in Objective-C.

Under ARC projects, compiler release and deallocate an object automatically. But, The ARC is not the same thing as garbage collection, as there is no background process doing the deallocation of objects. But it is a compile time process to manage the memory.

Here is an important thing in ARC, ARC never releases the strong objects in our application and the default property of an object declared in our (.h) class is strong. So, these variables will never get release. To release this variable a programmer has to write logic in his (.m) file to make these strong variable nil when we are not using it.

As in Non ARC application a developer call method release to decrease the rertianCount of an object or to manage the memory in application, In ARC project it is the programmer's responsibility to make these objects nil. Nilling these object references says to ARC that the application will not use this memory after nilling the references. In the situation when no any reference variable is referring to the memory, ARC releases the memory.

In ( Non ARC)

AViewController *objVC = [[AViewController alloc] init];

[self.navigationController pushViewController:objVC animated:YES];

[objVC release];

In ( ARC)

AViewController *objVC = [[AViewController alloc] init];

[self.navigationController pushViewController:objVC animated:YES];

objVC = nil;

Reference cycles are not handled by the ARC it is up to the programmer to break cycles using weak references. A reference cycle simply means one or more objects referencing each other, such that if you drew it out on paper with arrows representing the dependencies you would see a cycle.

strName1 = nil;

strName1 = strName2;

strName2 = nil;

strName2 = strName1; 

If you hold a reference of an object in multiple classes that are interconnected for message passing, in this situation ARC will never clear the memory. So, for every assigning and passing reference programmer has to nil the reference after using it OR, The programmer has to disconnect all the references after using the object.


Posted Queries
Posted By: jannet77 ghkkjk Reply:Programmer's Role In Automatic Reference Cou
05 Oct 2017
It is possible to hire specialists to decide a problem, I would recommend this company of https://www.singsys.com/mobile-application-development.php you they quickly and on perfectly managed with my task.