[HELP] release issue !

macrumors newbie

Hello folks ,
Im new to the Macintosh programming world.
I recently started programming simple codes and once I used the saved word 'release' for memory management I got this error:
(Once I wanted to release an unwanted object)
ARC forbids explicit message send of 'release'
'relase' is unavailable: not available in automatic reference counting mode.

macrumors 603

2. When using ARC, you don't have to release. Indeed, direct use of release is forbidden (which is what your error message is telling you). All releasing is automatic. That what the "A" in ARC stands for.

3. If you're learning from a book or tutorial, exactly which one? And exactly where are you in the book or tutorial (i.e. which chapter and page, or which step of a multi-step tutorial).

macrumors 68040

Senor Cuete: This isn't how it works. The code prwsented for copy is fine. copy will create a new object, including allocating memory. The object returned will be owned by the caller, so ownership will need to be relinquished. The exercise is trying to show which methods (in this case alloc and copy) return objects you own vs the factory methods that return autoreleased objects. When you are done with objects you own you relinquish ownership with release. If you need to take ownership of an autoreleased object you do so using retain.

It looks like the example is meant to demonstrate "classic" reference counting memory management, but you set up your project with ARC, which handles acquisition and relinquishing of ownership for you. This means you no longer send release, retain or autorelease. It sounds like you need to turn ARC off on your project if you want to practice memory management.

-Lee

Edit:

Code:

NSDate * date2 = [[NSDate alloc] myDate copy];

This is nonsense, Senor Cuete led you astray (I'm sure with the best intentions), and this won't compile, though plenty of incorrect code will compile.

thread startermacrumors newbie

Senor Cuete: This isn't how it works. The code prwsented for copy is fine. copy will create a new object, including allocating memory. The object returned will be owned by the caller, so ownership will need to be relinquished. The exercise is trying to show which methods (in this case alloc and copy) return objects you own vs the factory methods that return autoreleased objects. When you are done with objects you own you relinquish ownership with release. If you need to take ownership of an autoreleased object you do so using retain.

It looks like the example is meant to demonstrate "classic" reference counting memory management, but you set up your project with ARC, which handles acquisition and relinquishing of ownership for you. This means you no longer send release, retain or autorelease. It sounds like you need to turn ARC off on your project if you want to practice memory management.

-Lee

Edit:

Code:

NSDate * date2 = [[NSDate alloc] myDate copy];

This is nonsense, Senor Cuete led you astray (I'm sure with the best intentions), and this won't compile, though plenty of incorrect code will compile.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.