Hey Ken: Your advice is really appreciated, and I will definitely look over the Memory Management Guidelines when I have a bit more time in my day. ;)
On 4/29/09 1:12 PM, "Ken Thomases" <k...@codeweavers.com> wrote: > On Apr 28, 2009, at 9:19 PM, Pierce Freeman wrote: > >> - (void)awakeFromNib >> { >> NSFileHandle *remoteConnection = [NSFileHandle >> fileHandleForReadingAtPath:@"/Users/user/Desktop/file.plist"]; > > The above does not promise to keep the NSFileHandle object around for > as long as you need it. It's not at all clear to me that - > readToEndOfFileInBackgroundAndNotify retains the file handle for its > duration. > > So, you need to manage the lifetime of the file handle by retaining it > here and releasing it when you know you're done with it. > >> >> [[NSNotificationCenter defaultCenter] addObserver:self >> selector:@selector(readAllTheData:) >> name:NSFileHandleReadToEndOfFileCompletionNotification >> object:remoteConnection]; >> [remoteConnection readToEndOfFileInBackgroundAndNotify]; >> >> } >> >> - (void)readAllTheData:(NSNotification *)note { >> NSString *errors = nil; >> NSData *contentsOfDockFile = [note object]; >> NSLog(@"%@", contentsOfDockFile); >> NSDictionary *testing = [NSPropertyListSerialization >> propertyListFromData:contentsOfDockFile >> mutabilityOption:NSPropertyListImmutable format:nil >> errorDescription:&errors]; >> NSLog(@"%@", testing); >> >> [[NSNotificationCenter defaultCenter] removeObserver:self >> name:NSFileHandleReadToEndOfFileCompletionNotification object:[note >> object]]; >> >> [testing release]; >> } > > > On Apr 28, 2009, at 10:15 PM, Pierce Freeman wrote: > >> I added [testing retain] after the declaration of >> the variable, and I no longer get the wheel of death and my app >> freezing up. > > This smacks of flailing without understanding. > > The problem with your original code is that -propertyListFromData:... > gives you an object, but does not give you the right/responsibility > for releasing it, and yet you were releasing it anyway. > > While it is technically correct to solve this by adding [testing > retain], it is redundant. You could have just removed your [testing > release]. The object is guaranteed to live at least until you return > out of your -readAllTheData: method, so you need not retain it. And, > if you don't retain it, you should not release it. > > All this is to concur with Adam's suggestion that you reread the > memory management guide. > > Regards, > Ken > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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/archive%40mail-archive.com This email sent to arch...@mail-archive.com