Quote:
Originally Posted by BigBearStudios
Does the leak detetctor work properly? Its telling me theres leaks even when i just initialise a MutableArray like so:
m_entityArray = [[NSMutableArray alloc] initWithCapacity: (int)(MAX_WEAK_ZOMBIES + MAX_CHUNK_ZOMBIES )];
Im not adding anything after that, just reserving space.
|
What you're describing makes sense to me. Maybe you don't fully understand what Instruments is telling you when it "reports" a leak? It is essentially saying: "I've found a chunk of memory that you have allocated, but nothing in your code is referencing (pointing to) this chunk, and here's the line of code that allocated the chunk." When you alloc/init an NSMutableArray, even though the array itself is empty, there is space (memory) allocated for the array container itself. That's what is leaking in this case, according to Instruments.
I suspect your leaks are occurring when you reassign variables that are currently pointing at something else, without first properly cleaning up the existing value. That's a classic coding "leak", and not unique to Obj-C, illustrated by this simple C code:
Code:
unsigned char * buffer;
buffer = malloc( 1024 * 1024 ); // allocate a buffer
// do something with buffer
buffer = malloc( 5 * 1024 * 1024 ); // allocate another buffer
// Oops, just reassigned buffer without first cleaning it up. That's a 1MB leak.