Here's one problem:
Code:
NSString *num = [NSString alloc];
num = [formatter stringFromNumber:n];
You alloc some memory for a string, and you never use that memory or release it. It's probably getting leaked.
Your code basically says "reserve some memory for a string, and point the pointer 'num' at it." And then "point the pointer 'num' at a different string instead.' You don't need to alloc any memory if you're just going to point the pointer at a different object. This code would be just fine:
Code:
NSString *num;
num = [formatter stringFromNumber:n];
Also, it's more typical to release objects right after you add them to an array - that way when array gets deallocated, all the objects inside get deallocated too (because they only had a retaincount of one.)
I can see from your code that the objects in your array get a retaincount of two - one from when they were created, and one from adding to the array. That's why you find yourself having to release them after you remove them.
If you've added them to the array and then released them, then a simple [entities removeObject:theEntity] would cause the entity's retaincount to go to zero, and it would be destroyed. Futhermore, assuming the array had a retaincount of one, [entities release] would send a release to every object in the array, causing their counts to go to zero, causing them to be destroyed.
If what I'm saying seems confusing, then you should read up on memory management:
http://www.stepwise.com/Articles/Tec...-03-11.01.html