title: How can I track down memory peaks? (That's peaks with a p, not an l.)
body: <p>I've got a kiosk app, which, essentially shows a bunch of slides with various bits of information on them. I initially began coding this over a year ago, when I was beginning with Objective-C and iOS development. I find that my code style is much cleaner now than what it was, and I'm much more experienced, so I've decided to rewrite from scratch. </p>
  
  <p>I ran my app with the Allocations instrument to see what the memory usage was. Considering that this is a kiosk app, everything needs to run smoothly, without leaks. (Of course all apps need to run without leaks, but a kiosk app makes this an even more important goal.) I saw some interesting results, so I ran the old version of the code as well.</p>
  
  <p>Running the older version of the code, I see a pretty much even run at about 1.15 megabytes of memory usage. Everything seems to be allocated and deallocated as necessary. In my new implementation, however, I'm seeing something a little different. Memory usage keeps jumping in little "plateaus", and then eventually seems to peak out at about 1.47 megabytes of usage. Here's what the new Allocations report looks like after running for over 10 hours:</p>
  
  <p><img src="https://i.stack.imgur.com/O5gZB.png" alt="enter image description here"></p>
  
  <p>I'm concerned for several reason. </p>
  
  <ol>
  <li>The odd pattern in the beginning of the run.</li>
  <li>Allocations <em>seems</em> to peak at 1.47 megabytes, but running it overnight shows that it actually will slowly use more and more memory over time. That can't be a good thing.</li>
  </ol>
  
  <p>There are several notable differences between the old project and the new one. </p>
  
  <ul>
  <li><p>The older one uses Plists as a backing store (I manually read and write to a plist file.) The new project uses Core Data.</p></li>
  <li><p>The new project implements a library that is called on each "slide" that the old project didn't have. I'd be more concerned about this library, except I wrote it and I went through it to make sure I was releasing everything and only autoreleased wherever manual releases were impossible.</p></li>
  <li><p>Both classes use a factory class to create the slides. In the old project, the factory class was a singleton. I thought that making it into a normal class would help with the memory issues, since the singleton was never released. (Hence <em>it's</em>  properties were not being released.In the new project, the factory class is being released so I'm not sure why it's still taking up all that memory (if that's what's causing the problem.</p></li>
  <li><p>The old project makes use of string constants in various places. The new code uses a massive enum for the same thing. (The new code in general uses more constants.)</p></li>
  </ul>
  
  <p><strong><em>What can I do to track down memory peaks? The memory is all being cleaned up by the application when it discards whatever it's using, but it doesn't seem to be discarding things until the app terminates.</em></strong></p>
  
  <p>I'd be grateful if anyone would help point me in the right direction.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>It <em>looks</em> like the peaking is being caused by calls to the <a href="http://github.com/MosheBerman/KosherCocoa" rel="nofollow noreferrer">KosherCocoa</a> library. If anyone would mind taking a look at it and telling me what I'm doing wrong there as far as memory management goes, I'd really appreciate it.</p>