views:

130

answers:

1

Hi,

I hate having memory leaks and usually pride myself on, blah, blah, blah. Help!

The leaks I have aren't crazy big (a few K at max), but I want to remove them for sure. There are two categories of leaks and I've got some screen shots of each from Instrument's Leaks tool.

The first is just some odd Java/Web thing that happens within 10 seconds of running my app: Regardless of what code branch I take. It's like something is happening in the background that is causing it. I have some sample code from well respected authors of iPhone programming and theirs does the same thing, so I'm not worried too much about the 64 bytes I lose during my app run. This leak will occur long before I create any of my web-based forms such as MapKit tools like the reverse geocoder... but I do use them later in my code.

The second, however is insidious and I feel like a fool for not being able to track it down... because making it occur is so SIMPLE. All I do is create a UITextField in Interface Builder and use it like every other time I've ever done before. It happens on any UITextField I create whenever the iPhone pops up the virtual keyboard. And, the memory leaks are pretty substantial (hundreds of bytes at a time); presumably from the graphics involved with creating the on-screen buttons.

So, to be clear, when I touch inside of any of these text fields, the virtual keyboard pops up and I leak a few hundred (or more) bytes. I don't even type anything, assign any variables, etc. It only happens the first time the virtual keyboard pops up per text field, by the way. (So my leaks are "somewhat contained.") (That's what they said about a recent oil well, eh?)

You're going to ask what's different about the controller that owns these UITextFields. Well, the only thing I can think of is that it's a dynamically created UIViewController that is being managed by a UINavigationController.

Since in both of these cases, my code never shows up on the stack, I'm not sure what my next steps should be. I've run the new XCode static analyzer and while it reported a couple of warnings, they are benign red herrings.

So, I'm looking for advice on what my next steps should be. (I've begun the process of commenting out code, going to backups, etc.)

Screen shots of the Leaks tool attached.

Looks like I can only include one link until I get some rep points. I'll show the latter leak.

Memleak 2 screen shot: link text

-Pete

P.S. I'm using the latest Xcode (3.2.3) as of today with the newest 4.0.2 iOS.

+2  A: 

People new to Instruments tend to look only at the pretty graph and tend to get a bit misled by it. You should pay attention to the numbers not the graphs.

According to your screenshot, those are memory leaks from the libraries you are using. Notably these frameworks:

  • JavaScriptCore
  • Webcore
  • GraphicsServices

As the frameworks are causing these leaks, there is nothing you can do about it unless you have the source code.

According to your screenshot:

Total amount of memory leaked: 240 bytes (0.23 kb).

Not even a single kilobyte, so I wouldn't lose any sleep over it :P

Brock Woolf
Brock, thanks for your thoughts! The amount leaked grows as I click on other text fields. I have about 10 in all, so I end up with a couple of K leaked. I'll try not to sweat it too much, but I hate mysteries like this because I worry that I'm missing some key concept.
VTPete
It's not a mystery. Frameworks have memory leak bugs, the ones you are seeing might not actually be leaking memory, it's just that instruments is assessing what the framework is doing incorrectly and the data is actually retained somewhere inside. Unless its causing any major issues I would not worry too much
Brock Woolf