[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bogus retain via NSEnumerator

From: Uli Kusterer
Subject: Re: bogus retain via NSEnumerator
Date: Sun, 02 May 2004 12:35:52 +0200
User-agent: MT-NewsWatcher/3.3b1 (PPC Mac OS X)

In article <address@hidden>,
 Michael Ash <address@hidden> wrote:

> Any object you get back from a method that's not "alloc", "copy", or
> "retain" (plus the variants like mutableCopy) is autoreleased.

Danger, Will Robinson!

 This is a rough guideline for use, but not quite correct.

 Actually, the only guarantee you get is that you're not responsibe for 
releasing it if there's no "alloc", "copy", "retain", "load" or "new" in 
the name (load is a special case, but worth mentioning if you're 
manually loading NIBs).

 However, they're not necessarily autoreleased. They may be singletons, 
or they may be owned by the object you got them from.

 Take as an example objectAtIndex:. If you retrieve an object using this 
call from an array, you get a pointer to the object. You're not 
guaranteed that it'll be autoreleased. If you delete the array after 
calling objectAtIndex:, chances are your pointer to the object will be 
invalid as well, unless you have retained the object explicitly to 
prevent this.

 Many objects *do* return autoreleased objects, however, and when 
writing your own code, it is a good idea to do that yourself, because 
it's one of the things that helps your app be thread-safe, and prevent 
other bugs.

-- Uli

reply via email to

[Prev in Thread] Current Thread [Next in Thread]