coder
coder

Reputation: 10520

Objective-C: Why is this a memory leak?

I am getting a memory leak in my objective-C code that I don't understand. I have this code in a method that gets called several times:

AnalyzeBpm *analyzer  = [[AnalyzeBpm alloc] init];  

while( sample != NULL)
{
//do something with analyzer
}

[analyzer release];

When I run this code through Instruments, I get a leak everytime I allocate Analyze Bpm(which is a couple of hundred times). I looked at my AnalyzeBpm class, and everything I allocate in that class gets freed or deallocated. So why is this code creating a memory leak?

Upvotes: 1

Views: 134

Answers (2)

bbum
bbum

Reputation: 162712

When Instruments identifies a leak, it is showing you the line of code that is allocating the leak, not the line of code that causes the leak.

Somewhere something is retaining analyzer without releasing it. You need to find that unbalanced retain. It may or may not be in the AnalyzeBpm class.

Upvotes: 5

Jon Reid
Jon Reid

Reputation: 20980

Your alloc-init and release are balanced, so it has to be something else — something in your while loop.

Upvotes: 3

Related Questions