Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jokode

macrumors newbie
Original poster
Dec 14, 2008
16
0
Hi,
I have just noticed when testing my app against the Object Allocations tool, I am getting a ton of objects being allocated in the category of "CFArray (store-deque)".

I have just isolated the problem down to this line:
[myArray removeObjectAtIndex:0];

This line is being called in my main engine on every loop cycle, so I am getting a lot of these being allocated.

I have had a look around online but don't seem to be able to find a good explanation or a workaround. Does anyone have any idea why this is happened?

Thanks,
Joe.
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
Hi,
I have just noticed when testing my app against the Object Allocations tool, I am getting a ton of objects being allocated in the category of "CFArray (store-deque)".

I have just isolated the problem down to this line:
[myArray removeObjectAtIndex:0];

This line is being called in my main engine on every loop cycle, so I am getting a lot of these being allocated.

I have had a look around online but don't seem to be able to find a good explanation or a workaround. Does anyone have any idea why this is happened?

Thanks,
Joe.

We would need to see the rest of your code to know what is happening. An object will be released when you remove it from the array, but if you have retained it more than necessary elsewhere, it will leak when you remove it from the array and no longer have a pointer to it.
 

Jokode

macrumors newbie
Original poster
Dec 14, 2008
16
0
Thanks

Thanks admanimal.

I have just added a new line
[[myArray objectAtIndex:0] release];
[myArray removeObjectAtIndex:0];

which has solved the problem - until I figure out where I am retaining it!

Thanks again.
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
Thanks admanimal.

I have just added a new line
[[myArray objectAtIndex:0] release];
[myArray removeObjectAtIndex:0];

which has solved the problem - until I figure out where I am retaining it!

Thanks again.

If you are creating the objects you put into the array using an [[NSObjectName alloc] init...] style method, you should generally release the object right after you put it into the array, since they will already have a retain count of 1, which will be increased to 2 after being placed in the array.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.