Hello again, in my further study's of Objective-C, I have delved
deep into memory management, and I am stuck on a few minor details that I would like to have cleared up. First of all, look at this code:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> #import <font color = red>"Controller.h"</font>
@implementation Controller
- (IBAction)goButton

id)sender
{
NSString *tmpString;
tmpString = [self returnString];
[textField setStringValue:tmpString];
}
- (NSString *)returnString
{
NSString *poo = [[NSString alloc] initWithString:<font color = orange>@"hello mada"</font>];
[poo autorelease]; <font color = brown>// where will poo be autoreleased? why would you even want</font>
<font color = brown>// to allocate memory to it? why not make it a temporary</font>
<font color = brown>// string?</font>
return poo;
}
@end
</font>[/code]
I have read up on a few examples, and this one seemed to be the most widely used. However, in returnString, why would anyone ever want to have a allocated string that they are just going to deallocate soon anyways? Why not just make it a temporary string (not sending it an alloc message) and return that? Anyways, so we autorelease it, poo is gone at the end of the method, right? And then we return it, would it be OK to do this?:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> - (NSString *)returnString
{
NSString *poo = [[NSString alloc] initWithString:<font color = orange>@"hello mada"</font>];
return poo;
[poo release];
} </font>[/code]
finally, why isn't that you can't just send an object a dealloc message as soon as your done with it? And not have to worry about releaseing it and such.
Oh yes, sorry for the lengthy post, but one last thing please. Again, I am having trouble with understanding pointers.
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> -(NSCalendarDate *)entryDate
{
return entryDate; <font color = brown>//entryDate was declared in the header file.</font>
} </font>[/code]
Alright, so here we're returning an NSCalendarDate, and what's going to accept that is probably going to be another NSCalendarDate instance. But that would be a pointer, so, we would have a pointer to a pointer. Kind of like this or something:
entryDate2 = *entryDate;
OK, heh, thanks in advance, and I am reading other materials, but none of them really explain things too well.
[ 02-23-2002: Message edited by: itistoday ]