Wednesday, June 22, 2011

Memory Management in iPhone

In Mac OS X we have 2 options for memory management:
  • Reference Counting.
  • Garbage Collection(GC).
But, in iPhone there is no Garbage Collection(GC), it uses Reference Counting only.
Reference Counting also called as Retain Counting and Managed Memory.

Now, what is Reference Counting?

Each object keeps a count of how many other objects are using it (it is discussed in terms of Ownership).

If we create an object i.e. receive an object from a method that begins with alloc or new or contains the word copy, it means we own the object, and it reference count becomes 1.

If we receive an object from other method, we do not own the object. If we want to keep the object i.e. store it in an instance variable, we have to take ownership of that object by sending it a retain message, which increment it's retain count by 1.

We may also take ownership by copying the object  if it is capable of being copied, the object class must implement copyWithZone: .

If we own an object by any above method, we must relinquish our ownership by sending a release message to the object, which decreases its reference count by 1.

When an object's reference count becomes zero (0), the object is deallocated and its memory is returned to the heap.

If a release message causes an object's retain count to drop to zero(0), the release method  invokes the object's dealloc method.

Will be continue…...

Friday, June 17, 2011

iPhone Application Deployement(Part III)

(return to Part I)

(return to Part II)

Follow these steps to install application on device:

  1. Double click on cash.ipa, it will open in iTunes.
  2. Connect the device, it will also detect in iTunes.
  3. Now go to the "App" tab on the top.

4.Now mark the Sync Apps check box.

5. Mark the check box for cash in the application list and Press Sync then Apply.

Happy Installation :)


iPhone Application Deployement(Part II)

(return to Part I)

In this part we need to do some settings in xcode :

8. Drag the provisional certificates to Xcode or double click on it, it will automatically open in xcode
9. Open your project -> right click on the project under Groups&file -> click Get Info.

10. Now click on Configuration tab-> Duplicate Release -> Rename to Distributive -> then close this window.

11.Under Groups and Files in left panel click under Target, select Build tab and set Configuration to Distribution, then below on Code Signing Identity select iPhone Distributive example.

12.Click on Properties tab. In Identifier field type the App id suffix name ( that is the bundle identifier portion of the App id. After completion close the tab.

13.Click on any class in the project(for example : go to classes and double click on any file with extension .h) -> select Distributive(Device – 3.1 | Distributive)

14.Click on the class window once -> click File-> New File-> iPhone OS -> Code Signing ->Entitlement -> Next-> provide name of the file(Please copy the name by selecting it after typing, it will be useful in later part). ->in Location field delete /Classes -> Finish.

15. After finishing the Entitlement, one pop up window will appear showing the entitlement file. You can see the name of the file on top middle. 

16.Go to project in Xcode-> select Target (not Target but under Target) -> click Get Info -> go to Build tab -> Code signing Entitlement -> enter the entitlement file name along with the extension.

17.Now again check the Code Signing Identity and select the correct one and close this.

18. Click Build.(Please see the build log report in the Build ->Build Result, if not successful then check if the Keychain Access has double entry of the same certificate, in that case delete the old certificate, an also create entitlement under the folder prior to classes because the entitlement file is not found as it was created inside the classes folder previously)

19. Now there are 2 ways to give build to the client :

      19.1 Click under Product in Xcode – Highlight Products> right click Reveal in Finder.

                   Change the display view to column which shows the icon in columns.

Now under Distribute-iphoneos right click the application and create compressed file. Copy the zip file and give it to the client.

19.2    After Build(in step 18), again go to Build-> Build and Archive.

Organizer window will open. Click on Share… button.

Click on Save to Disk… button.

Click on Allow button.(some times it ask twice for allow.)

When you will save it as cash, a file named as cash.ipa will generate.

continue to Part III