What is Memory Management in Objective C?

Objective C wants you to manage memory for every Object you create, you don't have to do this with ints, chars, floats and bools but just objects. it doesn't matters whether those object are coming from your classes (or) frameworks. whenever you own a object by doing alloc, new, copy and retain you should make sure that its your responsibility to release that Object.

                      In many languages like Java, C#, ruby, python etc you just make the variables you need and language itself takes care of cleaning up the stuff. This is usually done by the part of the language named Garbage Collector. Even Objective C has kind of garbage collector but wasn't actually part of the language, they just added couple of years back. Garbage collector can't be used on iPhone , iPad and mac prior to Leopard so if you have to write code for those you have to do manually.

                      Garbage collection is never default in Object C, you have to choose and change the settings in the project you are working and often write code to opt into garbage collector. To even use Garbage collection you have to understand the manual memory management

For more information on how we can manage memory in different ways read Difference between Release and Autorelease

No comments:

Post a Comment