Re: NSArrays and tableView delegates
Re: NSArrays and tableView delegates
- Subject: Re: NSArrays and tableView delegates
- From: Ashley Clark <email@hidden>
- Date: Thu, 4 Dec 2008 17:25:20 -0600
On Dec 3, 2008, at 10:05 PM, Steven Hamilton wrote:
Hi folks,
Hi!
I have a subclassed NSWindowController. In this class I have a
method that extracts data from my core data model and formulates an
array of dictionaries. Also in this class I have the tableview
datasource methods. The datasource methods use the standard KVC
column identifier thingies to populate the table. I'm having memory
leaks and I'm sure its because of the way I'm making the array
available to teh data source methods.
My interface file looks like this;
@interface MLimportController : NSWindowController {
IBOutlet NSTableView *transactionTable;
IBOutlet NSArrayController *accountsController;
NSMutableArray *importedTransactions;
NSManagedObject *selectedAccount;
NSNumber *selectedTransferIndex;
}
- (IBAction) recordTransactions:(id)sender;
- (IBAction) deleteSelectedTransactions:(id)sender;
- (void) setAccountSortDescriptors: (NSArray *) descriptors;
- (NSArray *) accountSortDescriptors;
- (void) importFile:(NSString *)aFile;
//delegates
- (int)numberOfRowsInTableView:(NSTableView *)tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:
(NSTableColumn *)tableColumn row:(int)row;
- (void)tableView:(NSTableView *)tableView setObjectValue:
(id)newValue forTableColumn:(NSTableColumn *)tableColumn row:(int)row;
@end
In the importFile: method is where I build they array
importedTransactions. However, as it will autorelease I [retain] it
so its still hanging around for the tableView methods to access it.
Is this the correct way of doing this? Or should I be declaring the
NSArray as a @property and using getters/setters to use it?
That sounds fine as long as you are releasing it in your -dealloc
method.
My memory leak is resulting in importedTransactions always having a
retainCount of 1, meaning the importController class can never be
deallocated by my NSDocument, meaning the documentController can
never close the document properly. I'm sure I'm doing this an ugly
way.
The retainCount of the importedTransactions will not affect whether
its containing class is deallocated unless one or more items in that
array have retained the importController class also. If they have then
you have a circular reference that you'd have to break at some point
external to -dealloc.
(Leopard 10.5.5 with GC on)
If you're running this program under GC then none of what you said
makes sense anyway since retain/release/autorelease are all no-ops
under GC and -dealloc is never called there.
What tool told you that you were having leaks? What information did it
give you?
Ashley
_______________________________________________
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