Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Basic Obj-C Question on Memory and Strings



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.