Hi,
I noticed that the SCTableModel's section and correlating cells seem to be keeping a strong reference to their bound object even after deallocation and consequently, the bound object's dealloc method doesn't get called.
Here is a gist of my implementation:
///SettingsContainer.h /*The object to be bound to the SCTableModel*/ @interface SettingsContainer : NSObject @property(nonatomic, copy) NSString* userId; @property(nonatomic, copy) NSString* authId; @property(nonatomic, copy) NSString* password; @end ///SettingsContainer.m @implementation SettingsContainer + (SCClassDefinition*)classDef { return [SCClassDefinition definitionWithClass:[self class] propertyNames:@[@"userId", @"authId", @"password"] propertyTitles:@[@"User ID", @"Auth ID", @"Password"]]; } - (void)dealloc{ //This method is never invoked } @end ///SettingsViewController.m /*Manages the scTabelModel*/ @interface SettingsViewController() @property (nonatomic, weak) IBOutlet UITableView *tableView; @property(nonatomic, strong) SettingsContainer *settingsContainer; @property(nonatomic, strong) SCTableViewModel *scTableModel; @end @implementation SettingsViewController - (void)viewDidLoad { [super viewDidLoad]; self.scTableModel = [SCTableViewModel modelWithTableView:self.tableView]; SCObjectSection *accountSection = [SCObjectSection sectionWithHeaderTitle:@"Account" boundObject: self.settingsContainer boundObjectDefinition: [[self.settingsContainer class] classDef]]; [self.scTableModel addSection:accountSection]; } - (void)dealloc{ //This method is invoked as expected } @end
As the comments point out, when SettingsViewController is dismissed it's dealloc method is entered as expected, however the SettingsContainer's dealloc method isn't. Viewing Xcode's memory usage report the graph doesn't appear to rise because of this, however I am relying on this dealloc method to handle some other code cleanup.
Some further investigation showed me that after "sectionWithHeaderTitle:boundObject:boundObjectDefinition" is called, self.settingsContainer's retainCount increases by 4. I assume this is due the generated section table binding to it and the 3 generated cells ("User ID", "Auth ID", and "Password"), which makes sense. With this in mind I tried implementing the following code:
@implementation SCTableViewModel (cleanup) - (void)releaseBoundObjects { for (int i = 0; i < self.sectionCount; i++) { SCTableViewSection *section = [self sectionAtIndex:i]; for (int j = 0; j < section.cellCount; j++) { [section cellAtIndex:j].boundObject = nil; } section.boundObject = nil; } } ///SettingsViewController.m @implementation SettingsViewController - (void)dealloc { [self.scTableModel releaseBoundObjects]; } @end
Now upon execution of "releaseBoundObjects", my SettingsContainer's dealloc method is successfully entered.
Is there a better way to handle this kind of situation?