Re: Files and arrays
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.