vruzeda
vruzeda

Reputation: 1

Memory Leak in NSString, NSArray

I'm developing a custom framework (and, of course, an CocoaTouch application to test it). It's a large framework, hence it will be impossible to post it here (besides it not being open source, not my fault, I swear!).

I've been trying for quite a while, but I can't possibly find the answer: Instruments is accusing some leaks in my application. I'm really newbie, so, I don't know if I'm misinterpreting the reports, but it seems methods like

[NSArray array]
[NSString stringWithCString:encoding:]
[NSString stringWithFormat:]
[NSString stringWithUTF8String:]
[_obj_rootAlloc]
[__NSArrayM]

are some of the main reasons, and that really don't make any sense to me.

In this link, you can find the Instruments' runs' reports. Could anyone please take a look and see if that can possibly mean anything?

Upvotes: 0

Views: 264

Answers (2)

vruzeda
vruzeda

Reputation: 1

The actual problem was an assumption I made about synthesized properties. I had something like this:

@interface MyClass : NSObject

@property(nonatomic,retain) NSString *myProperty;

@end

And in the implementation:

@implementation MyClass
@synthesize myProperty=_myProperty;

@end

I assumed that the @synthesize would also autorelease the property, but that was my mistake. I fixed it doing:

@implementation MyClass
@synthesize myProperty=_myProperty;

-(void)dealloc
{
    [_myProperty release];
    [super dealloc];
}

@end

Thanks for the help!

Upvotes: 0

Chuck
Chuck

Reputation: 237060

Instruments reports where the leaked objects were created, not the point at which they become an official leak. Somewhere, the objects you're creating with those methods are either being overretained or not released when they should be.

Upvotes: 4

Related Questions