views:

375

answers:

4

In Xcode I run the program I wrote with the leaks instrument

It says leaks are discovered and the total leaked bytes keeps rising.

I look at leaked objects and none of them seem to be from my program.

For example QuartzCore OpenGLES libLLVMContainer.dyl libCoreVMClient.dylib libGFXShared.dylib

Is it my fault that the program is leaking memory or is this just bad code written by apple and should be expected?

+3  A: 

A typical program will make calls into 3rd party libraries, e.g. GUI frameworks. If the program doesn't release the resources it allocates, they won't be destroyed. So yes, it's probably your fault!

Daniel Earwicker
+1  A: 

I'm guessing apple doesn't have memory leaks. They have instruments as well. They definitly did testing. The only time I've ever heard of leaks is in the UIKit webview. I'd do some reading on instruments and make sure you're reading the stack right.

Sam
A: 

use build and analyze to find them

Matt S.
+8  A: 

There are always a leak or two in Apple's frameworks if you really look for them (which is a part of my day job). But generally nothing severe, nor leaks that occur in relatively common / standard code.

The first step is to use Build and Analyze to do a basic sanity check of your code. It will catch many potential leaks, but not all.

Then use Instruments. When you find a leak down in an Apple library, look at the stack trace of the allocation. Specifically, look for the lowest frame that is in your code. That is typically where your leak will be.

Think of it this way; your code calls into an Apple framework which may call through to other Apple libraries and frameworks. When the Apple code returns, it hands you back a piece of memory. If you don't manage that memory properly, a leak may be created.

bbum
I also read that the leaks that show up in the simulator are different then what may show up on the device. So I am going to switch to device testing.
Mel
Yup -- the differences aren't huge, but there are differences. Start with simulator focused analysis then move to device focused as you polish for release.
bbum