• 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
Another memory question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Another memory question


  • Subject: Another memory question
  • From: James Ludtke <email@hidden>
  • Date: Tue, 26 Aug 2003 14:53:54 -0400

In the code fragment below I reassign a new value to an
NSString. (I have seen others do that as well.)

- (void)awakeFromNib {

NSString *demoFile;

demoFile = [NSString stringWithString: @"~/Application User
Data/dsf.plist"];
demoFile = [demoFile stringByExpandingTildeInPath];
// more code
}

If I have understood it correctly, the second assignment creates
a new memory block for the string, and the first string is still
in memory, but can no longer be accessed.

My questions are:

1) Will the auto release process release the first block or
will there be a memory leak?

2) Is the above example good practice, or would the following
have been better:


- (void)awakeFromNib {

NSString *demoFile;

NSString *temp = [[NSString alloc] init];
temp = [NSString stringWithString: @"~/Application User Data/dsf.plist"];
demoFile = [temp stringByExpandingTildeInPath];
[demoFile release];
// more code
}
_______________________________________________
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.

  • Follow-Ups:
    • RE: Another memory question
      • From: "Jonathan E. Jackel" <email@hidden>
    • Re: Another memory question
      • From: Glen Simmons <email@hidden>
    • Re: Another memory question
      • From: Jörn Salewski <email@hidden>
  • Prev by Date: Re: Help me, which book I should buy to learn Cocoa??
  • Next by Date: Re: NSString -> char* ? Use -[NSString UTF8String].
  • Previous by thread: NSOutlineView question solved
  • Next by thread: Re: Another memory question
  • Index(es):
    • Date
    • Thread