• 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: NSArrays and tableView delegates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSArrays and tableView delegates
      • From: Steven Hamilton <email@hidden>
References: 
 >NSArrays and tableView delegates (From: Steven Hamilton <email@hidden>)

  • Prev by Date: Re: custom view binding to NSTreeController
  • Next by Date: indexOfObjectIdenticalTo: problem with NSArrayController
  • Previous by thread: NSArrays and tableView delegates
  • Next by thread: Re: NSArrays and tableView delegates
  • Index(es):
    • Date
    • Thread