Article Preview
Buy Now
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.