I canโ€™t understand why a memory leak occurs here.

I have the following block that gives me problems in the performance tool: in particular, it says that STObject is leaking. I'm not sure why?

for (NSDictionary *message in messages)
{
    STObject *mySTObject = [[STObject alloc] init];

    mySTObject.stID = [message valueForKey:@"id"];

    [items addObject:mySTObject];
    [mySTObject release]; mySTObject = nil;

} 
[receivedData release]; receivedData=nil;
[conn release]; conn=nil;

UPDATE:

is this a property of @property (non-atomic, conservation), will this result in a hold value of +2?

+3
source share
4 answers

- NSArray NSDictionary, , mySTObject , , , - , nil. , , "" .

+6

/, STObject? , STObject "- (void) dealloc" ). , STObject , , STObject, .

dealloc :

- (void)dealloc {
    [stID release];
    [myVar2 release];
    [myVar3 release];
    [super dealloc];
}

, [super dealloc] .

+4

10.6, Xcode " ", , .

0

mySTObject ...

        [mySTObject release]; mySTObject = nil;

just delete mySTObject = nil;I think it should be ..

-4
source

Source: https://habr.com/ru/post/1760292/


All Articles