1

I have a navigation based template, when I run my application using Instruments, the very first memory leak comes under:

Leak Object: Malloc 128 bytes 
Responsible Library: CoreGraphics 
Responsible Frame: open_handle_to_dylib_path

I don't know where this leak is coming from and how remove this.

If it's a default leak, then I think I don't need to worry about it. But if it's not then I have to find a way to remove the leak.

John Topley
  • 113,588
  • 46
  • 195
  • 237
iPhoneDev
  • 2,995
  • 4
  • 33
  • 44

2 Answers2

2

Expanding on deanWombourne perfectly correct answer a bit..

The Leaks Instrument shows you memory that isn't going to be free'd in the normal course of the app (because there aren't any references to it). This in itself is no biggie, it will be free'd when the app exits. A lot of the framework code will allocate and leave these very small chunks of memory allocated. I have no idea if they are mistakes or essential to how the app runs. Whatever, we must accept that they are completely normal.

Leaks will identify these chunks of memory as 'Leaks' and that sounds bad, but this is not really the 'Leaks' that the instrument is there to help you identify.

The 'real' leaks are in the code that can be run many times and which allocate some memory that is never freed, so over time will consume more and more memory until all memory is used and your app will crash.

So if you have an app that no matter how long you use it for or no matter how you use it, it 'leaks' 128 bytes in an apple framework you generally don't have to worry.

However, if you have an app that say, every time you click a button it allocates a new string which is never released - no matter how many bytes the string is - if the user pressed the button enough times this would consume all the memory available to app and eventually crash it. This is the kind of leak you need to watch out for.

The leaks instrument realistically can't tell the difference between the two kinds, but you need to be able to. You might want a kind of singleton object, for example, that there is only ever one instance of, and that needs to exist for the entire lifetime of your app. You create the object on app startup and realistically you never need to free this object, it can be killed when the app exits. Leaks will flag it as a leak, and some other developers that you work with who assume that this means you don't know what you are doing will run to your boss like a little child and say "He's writing really leaky code, and that's reeeeally bad". And your boss, who isn't a programmer will take him seriously because it does sound bad and anyway he scraped a 2.2 in CS from a reputable University so he must know what he's talking about. When really it is completely reasonable and exactly what you meant to do.

So, use the Leaks instrument to find bugs in your code that will ruin your app. Don't worry about every byte found 'Leaking' in an Apple framework.

hooleyhoop
  • 9,128
  • 5
  • 37
  • 58
0

If it's a one off 128 byte leak then don't worry about it at all, there are better ways to spend your time than thinking about this :)

deanWombourne
  • 38,189
  • 13
  • 98
  • 110