又一起 iPhone 内存泄漏事件呼救。寻求有关后续步骤的建议
我讨厌内存泄漏,并且通常为自己感到自豪,等等,等等。帮助!
我遇到的泄漏并不大(最多几K),但我想肯定地删除它们。泄漏分为两类,我从 Instrument 的泄漏工具中获取了每种类型的一些屏幕截图。
第一个是运行我的应用程序后 10 秒内发生的一些奇怪的 Java/Web 事情:无论我采用哪个代码分支。就好像后台发生了某些事情导致了这种情况。我有一些来自受人尊敬的 iPhone 编程作者的示例代码,他们的代码也做了同样的事情,所以我不太担心应用程序运行期间丢失的 64 字节。这种泄漏早在我创建任何基于 Web 的表单(例如反向地理编码器等 MapKit 工具)之前就会发生……但我稍后会在代码中使用它们。
然而,第二个是阴险的,我觉得自己像个傻瓜,因为无法追踪它......因为让它发生是如此简单。我所做的就是在 Interface Builder 中创建一个 UITextField 并像我以前所做的那样使用它。每当 iPhone 弹出虚拟键盘时,它就会发生在我创建的任何 UITextField 上。而且,内存泄漏非常严重(一次数百字节);大概来自创建屏幕按钮所涉及的图形。
因此,需要明确的是,当我触摸这些文本字段中的任何一个时,虚拟键盘就会弹出,并且我会泄漏几百(或更多)字节。我什至不输入任何内容,分配任何变量等。顺便说一句,这只发生在每个文本字段第一次弹出虚拟键盘时。 (所以我的泄漏“在某种程度上受到了控制”。)(这就是他们对最近的油井所说的,嗯?)
您会问拥有这些 UITextField 的控制器有什么不同。好吧,我唯一能想到的是它是一个动态创建的 UIViewController,由 UINavigationController 管理。
由于在这两种情况下,我的代码从未显示在堆栈上,因此我不确定下一步应该是什么。我已经运行了新的 XCode 静态分析器,虽然它报告了一些警告,但它们都是良性的转移注意力的东西。
因此,我正在寻求有关下一步应该采取的建议。 (我已经开始注释代码、进行备份等过程。)
附加泄漏工具的屏幕截图。
看起来我只能包含一个链接,直到我获得一些代表点。我将展示后者的泄漏。
Memleak 2 屏幕截图: 链接文本
-Pete
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚接触工具的人往往只看漂亮的图表,并且容易被它误导。您应该注意数字而不是图表。
根据您的屏幕截图,这些是您正在使用的库的内存泄漏。特别是这些框架:
由于这些框架导致了这些泄漏,因此除非您拥有源代码,否则您无能为力。
根据您的屏幕截图:
泄漏的内存总量:240 字节 (0.23 kb)。
连一个千字节都没有,所以我不会因此而失眠:P
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:
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