views:

131

answers:

1

I'm trying to test for memory leaks in my iphone and I'm not having much luck getting rid of this one. Here is the code that is leaking.


- (id)initWithManagedObjectContext:(NSManagedObjectContext *)aMoc delegate:(id)aDelegate runSync:(BOOL)aRunSync {
    if (self = [super init]) {
        self.moc = aMoc;
        self.settingsManager = [[VacaCalcSettingsManager alloc] initWithManagedObjectContext:self.moc];
        self.delegate = aDelegate;
        calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        self.runSync = aRunSync;
    }

    return self;
}

It is leaking on the self.settingsManager = [[VacaCalcSettingsManager alloc] initWithManagedObjectContext:self.moc]; line.

The self.settingManager instance variable is released in the dealloc method of the class.

I'm not sure what other information would be pertinent. Please let me know and I can provide it.

Thanks for any assistance.

-Mark

Here is the header file.


@interface VacaCalcCalculation : NSObject {
    NSManagedObjectContext *moc;
    VacaCalcSettingsManager *settingsManager;
    id delegate;
    NSCalendar *calendar;
    NSDate *nextBankLimitDate;
    BOOL runSync;
}

@property (nonatomic, retain) NSManagedObjectContext *moc;
@property (nonatomic, retain) VacaCalcSettingsManager *settingsManager;
@property (nonatomic, retain) id delegate;
@property (nonatomic, retain) NSCalendar *calendar;
@property (nonatomic, retain) NSDate *nextBankLimitDate;
@property (nonatomic) BOOL runSync;

- (id)initWithManagedObjectContext:(NSManagedObjectContext *)aMoc delegate:(id)aDelegate;
+7  A: 

If your settingsManager property is set to retain then you are retaining an object twice with the line: self.settingsManager = [[VacaCalcSettingsManager alloc] initWithManagedObjectContext:self.moc];

Try adding autorelease to the alloc]init or creating a class method on VacaCalcSettingsManager that returns an autoreleased object. Otherwise you could redeclare your property with assign so that it does not retain the object a second time.

jessecurry
or just assign directly to settingsManager instead of calling [self setSettingsManager:]
drawnonward