Xcode Instruments Detected Memory Leak: Why?

I was debugging the application that I am creating, but with the help of tools I found a memory leak that I cannot understand.

If I try to change the code following the β€œTools” sentence, my application will crash due to

sent to an exempted 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.datasourceis NSMutableArray, and specialObj.titleisNSString

They are defined as @property(nonatomic, retain).

My problem is that Tools tell me that these 2

ClassA *objA = (ClassA *)model;
ClassB *objB = (ClassB *)model;

are leaks, but if I release objAand objB, I crash the application.

Thanks for any help!

+3
source share
3 answers

: XCode , , .

, - , XCode, , .

, - !

0

, . , ARC, dealloc

[self setDataSource: nil];

[instanceVariableThatBacksDataSourceProperty release];

, Apple , KVO .

0

- . -, .

, , , Objective-C .

, - .

0
source

All Articles