[newbie] memory mgmt question
[newbie] memory mgmt question
- Subject: [newbie] memory mgmt question
- From: jay <email@hidden>
- Date: Sat, 20 Dec 2003 21:03:50 -0800
I've gone through all the memory management docs and tutorials and I
thought I had a pretty good hold on the concepts. Apparently not.
Here's a somewhat simplified case of what I'm having problems with.
I have a class "AClass" which checks a bunch of system variables
including the OS version. In the method definition I have:
@interface AClass : NSObject
{
IBOutlet id controller;
IBOutlet NSString *osVersion;
...
}
In the implementation I have a method like this:
- (NSString *)findOSVersion {
NSDictionary *dict = [[NSDictionary alloc] init];
// loads dict with
// /System/Library/CoreServices/SystemVersion.plist
dict = initWithContentsOfFile:[NSString
stringWithCString:SystemVersionPlist]];
NSString *version = [dict objectForKey:@"ProductVersion"];
[dict release]; // have tried it without the release
return [version substringToIndex:4]; // have tried with a
// retain
}
The above method is called on awakeFromNib and it sets the osVersion
instance variable with an appropriate setter method (retain, release,
assign).
In another class I have an instance of AClass. I want to get the
osVersion instance variable from it:
NSString *ver = [aClass osVersion]; // getter method, have tried this
// line with a retain as well.
Then I want to print it out. Uh oh.
NSLog(@"%@", ver); // for example
This return a bunch of 'garbage' characters to the terminal. However,
if I run:
NSLog(@"%@", [aClass osVersion]);
it prints it out correctly.
What exactly am I doing wrong? I know it's something simple, but I'm
missing it. If you need any more information or code just let me know.
Thanks much.
-j
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.