Chapter 6. Central Objective-C Concepts: Pointers, Data Types, and Memory Management

For new programmers, one of the attractions of JavaScript is that browser interpreter engines handle a lot of tedious interior management, reducing the amount of programmer planning and intervention required by compiled languages and environments. For instance, once you assign a value to a JavaScript variable, your code simply references that variable anywhere within the proper scope to get the existing value or assign a new one. Additionally, not only do JavaScript variables not care what type of data is assigned to them, but your code can assign a completely different type of data to the same variable with impunity (although it is a potentially dangerous programming practice, for maintenance purposes). Finally, JavaScript programmers don’t have to think about how their code impacts memory utilization. Your code generates objects and values at will, handing over the job of allocating memory and freeing unused memory to the browser. Even if you want to free memory by removing some object, you can’t force the browser to do so.

Objective-C and Cocoa Touch programming will (regrettably to some) cure you of those happy days. A variable no longer necessarily stores a value, but rather a location in memory where the data is being stored. You will need to add new sensibilities to the specific types of data being assigned to a variable or returning from a method. And you will be responsible for husbanding ...

Get Learning the iOS 4 SDK for JavaScript Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.