I was doing a debug on an application I'm creating, but running instruments I found a memory leak that I can't be able to understand.
If I try to modify the code following Instruments suggestion, my application crashes because of
message sent to deallocated instance
Can someone help me?
- (void) objectAtIndex:(int)index {
SpecialObject *specialObj = [SpecialObject sharedInstance];
id model = [self.datasource objectAtIndex:index];
if ([model isKindOfClass:[ClassA class]]) {
ClassA *objA = (ClassA *)model;
specialObj.title = objA.title;
} else if ([model isKindOfClass:[ClassB class]]) {
ClassB *objB = (ClassB *)model;
specialObj.title = objB.title;
}
}
self.datasource
is a NSMutableArray
while specialObj.title
is a NSString
They are defined as @property(nonatomic, retain)
.
My problem is that Instruments tells me that these 2
ClassA *objA = (ClassA *)model;
ClassB *objB = (ClassB *)model;
are leaks, but if I release objA
and objB
my application crash.
Thanks for any help!