Basic Obj-C Question on Memory and Strings
Basic Obj-C Question on Memory and Strings
- Subject: Basic Obj-C Question on Memory and Strings
- From: Matt Keyes <email@hidden>
- Date: Fri, 8 Aug 2008 05:35:04 +0000
- Importance: Normal
Hello again,
I have two basic Obj-C string question, please see the code below:
//.h file
@interface SomeClass : NSObject {
@private
NSMutableString *_someString;
}
@property (nonatomic, retain) NSMutableString *someString;
-(void)DoTheStringThing:(NSString *)aString;
@end
//.m file:
#import "SomeClass.h"
@implementation SomeClass
@synthesize someString = _someString;
-(void)DoTheStringThing:(NSString *)aString {
_someString = [[NSString alloc] initWithString:aString];
}
//in some other class...
-(void)foo {
SomeClass *cls = [[SomeClass alloc] init];
[cls DoTheStringThing:@"Here's a fun string."];
//HERE IS THE QUESTION:
//This causes a halt in the debugging and will sometimes give a _BAD_ADDRESS or something... simply checking the NSString pointer causes it
//I am having a hard time I guess understanding Obj-C memory management b/c in traditional C/C++ this would be fine to do
if(cls.someString)
{
self.txtMyTextBox.text = [[NSString alloc] cls.someString];
}
}
-(void) dealloc {
[txtMyTextBox release];
[super dealloc];
}
_________________________________________________________________
Get Windows Live and get whatever you need, wherever you are. Start here.
http://www.windowslive.com/default.html?ocid=TXT_TAGLM_WL_Home_082008_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden