Sunday, 11 May 2014

Memory related question and Answer

1) Copy 
 =>It creates a new object and when new object is created retain count will be 1.
 =>Copy will copy the data present in the memory location and will assign it to the variable so in the case of copy you are first copying the data from a location assign it to the variable which increases the retain count.
=>Copy works on value only 
=>Copying an object, however you do it, should create another object with duplicate values. Think of this as a clone. You do NOT share the clone with whomever passed it to you.

2 )Retain
=> It is done on the created object, and it just increase the reference count of an object.
=>Retain copies the reference (address) and increases the retain count and you have to take care of releasing that object.
=> Increases the retainCount of the receiver. An object is removed from memory - deadlocked, when retainCount is 0.
=>Retaining an object will increase its retain count by one. This will help keep the object in memory and prevent it from being blown away. What this means is that if you only hold a retained version of it, you share that copy with whomever passed it to you.

3) Release
   =>Relese  decreases the reference on an object
4)Dreain
 =>Drain is used in place of release on ONLY for NSAutoreleasePool objects due to some arcana related to the Objective C garbage collection

5) Dealloc
    =>Dealloc is called by the system once the retainCount of an object hits 0. It is where you clean up various things your object has (like a deconstructor or finalizer). You should NEVER call it directly, except for calling [super dealloc] at the end of your dealloc routines.

1 comment:

  1. Really I enjoy your blog with an effective and useful information. Very nice post with loads of information. Thanks for sharing with us..!!..iOS Online Course

    ReplyDelete