CristiC
CristiC

Reputation: 22698

Where is the leak here?

I don't understand where is the leak here.

I am querying for a field in the database. After this, I am inserting in a NSMutableArray list.

@property (nonatomic, retain) NSMutableArray *bList;

@property (nonatomic, retain) NSString *icon;//Model

Model *newModel = [[Model alloc] init]; 
newModel.icon = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 2)];
[self.bList addObject:newModel];
[newModel release];

And in the end:

- (void)dealloc {
    [self.bList release];
    [super dealloc];
}

Upvotes: 0

Views: 114

Answers (3)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

Based on your comment on @murat's answer, If you are doing,

self.blist = [[NSMutableArray alloc] init];

then you are leaking memory as you are taking ownership twice in that line. One by alloc-init and one based on the property (assuming it is retained, mostly should be). In such case releasing it once in dealloc won't balance the retain-release calls. You will have to rather do,

self.blist = [NSMutableArray array]; 

or

self.blist = [NSMutableArray arrayWithCapacity:100];

Upvotes: 1

bbum
bbum

Reputation: 162712

    [self.bList release];

Don't do that; either use self.bList = nil; or [bList release], bList = nil;

There doesn't appear to be a leak in that code, unless I'm missing something obvious.

Remember that leaks identifies where the leak was allocated, not where it was leaked. The leak is likely caused by an over-retain elsewhere.

Upvotes: 4

murat hacioglu
murat hacioglu

Reputation: 166

You create an instance of array but did not take a memory space for it. For your blist array, allocate a memory space.

self.blist= [[NSMutableArray alloc]init]; // or you can create like
self.blist= [[NSMutableArray alloc]initWithCapacity:100];

Upvotes: -2

Related Questions