• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Basic Obj-C Question on Memory and Strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Basic Obj-C Question on Memory and Strings
      • From: Charles Steinman <email@hidden>
  • Prev by Date: Re: Cocoa Dev Style: Using Class versus Object Methods
  • Next by Date: Re: Cocoa Dev Style: Using Class versus Object Methods
  • Previous by thread: [Moderator] Re: Need pointers on web service communication from the iPhone
  • Next by thread: Re: Basic Obj-C Question on Memory and Strings
  • Index(es):
    • Date
    • Thread