• 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
Re: Files and arrays
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Files and arrays


  • Subject: Re: Files and arrays
  • From: Ondra Cada <email@hidden>
  • Date: Sat, 16 Nov 2002 15:41:33 +0100

On Saturday, November 16, 2002, at 02:25 , Jim Balhoff wrote:

// caution - typed into Mail by a beginning programmer!

who, alas, just kind of copied down Jeff Knee's buggy code (or did you not?
), since...

NSString *fileContents = [[NSString alloc] initWithContentsOfFile:aFile];

...this would leak. What you actually wanted here was [NSString stringWithContentsOfFile:aFile].

NSMutableArray *personArray = [[NSMutableArray alloc] init];

This looks like the same problem, but, unlike the file contents string, the array we will need for longer. Therefore, it should indeed be created this way, but should be placed rather into an instance (or perhaps global)
variable than into an automatic one.

Person *aPerson = [[Person alloc] initWithString:nextPersonString];

This would leak again. What you actually wanted -- presumed Person does not have a convenience constructor -- was

aPerson=[[[Person alloc] initWithString:nextPersonString] autorelease]
;
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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: Files and arrays
      • From: Jim Balhoff <email@hidden>
References: 
 >Re: Files and arrays (From: Jim Balhoff <email@hidden>)

  • Prev by Date: Re: Sort Array
  • Next by Date: Fullscreen transparent background
  • Previous by thread: Re: Files and arrays
  • Next by thread: Re: Files and arrays
  • Index(es):
    • Date
    • Thread