Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 1.6

COLUMN

Memory Management in Cocoa

Issue: 1.6 (June/July 2003)
Author: Colin Cornaby
Author Bio: Colin Cornaby is an OS X developer. He is the author of Duality 4, a theme changer written in Cocoa for Mac OS X, and the ThemeKit development framework, for writing theme applications in Cocoa.
Article Description: No description available.
Article Length (in bytes): 5,578
Starting Page Number: 43
Article Number: 1623
Related Link(s): None

Excerpt of article text...

Memory Management in Cocoa

One of the scarier aspects of Cocoa can be memory management. For programmers who already work in languages that require memory management to be programmed, Cocoa's memory management is very easy to learn. However, programmers who write code in a language in which memory management is handled for them (such as Java or REALbasic) have a bit to learn.

Let's take an example using NSImage. All you need to know about NSImage for now is that it is a variable type that holds an image. In this example our NSImage will be named "foo". Before we can put an image into "foo", we need to create a space in memory. We then need to initialize that space, or in other words, get the space in memory ready to hold an NSImage. To do this we can use the "alloc" and "init" methods. Alloc will create space in memory for the image. Init prepares that space to hold an image. Here is how you might write some code to alloc and init "foo".

...End of Excerpt. Please purchase the magazine to read the full article.