|
|
#1 |
|
[HELP] release issue !
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. Hopefully you can help.. Oneill ! |
|
|
|
0
|
|
|
#2 |
|
1. Post your code.
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). |
|
|
|
0
|
|
|
#3 |
|
hey chown33 thanks for replying,
Answering your two questions: 1)Here is the code: Code:
NSString * message = @"Hello";
NSString * message2= [NSString stringWithFormat:@"The word is:%@",message];
NSString * anothermessage = [[NSString alloc] initWithFormat:@"The Word is %@",message];
NSDate * myDate = [NSDate date];
NSDate * anotherdate = [NSDate dateWithTimeIntervalSince1970:1234213];
NSDate * date2 = [myDate copy];
NSLog(@"The results are %@ , %@ , %@ , %@ , %@ , %@" , message, message2 , anothermessage , myDate , anotherdate , date2);
[anothermessage release];
[date2 release];
}
|
|
|
|
0
|
|
|
#4 |
|
I think that there's another error as well.
It looks like you didn't allocate space for date2. Shouldn't you do something like this: Code:
NSDate * date2 = [NSDate alloc]; |
|
|
|
0
|
|
|
#5 | |
|
Quote:
so you are saying if i want to copy I first need to allocate a space in the memory then copying it? Code:
NSDate * date2 = [[NSDate alloc] myDate copy]; |
||
|
|
0
|
|
|
#6 | |
|
Quote:
|
||
|
|
0
|
|
|
#7 |
|
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]; |
|
|
|
0
|
|
|
#8 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 10:04 AM.







Linear Mode
