为什么当我触摸 UIImageView 时会出现这种奇怪的内存泄漏?

发布于 2024-07-22 11:47:20 字数 781 浏览 3 评论 0原文

真的很奇怪。 我有一个空白的 UIImageView 子类,它实现 -touchesEnded:、-touchesMoved 和 -touchesBegan: 方法。 这些方法的实现都是空的。 他们只是什么都不做。 但是,当我使用“Leaks”运行 Instruments 时,触摸 UIImageView 并将手指移到 UIImageView 之外,同时仍触摸屏幕,我会收到来自 Instruments 的内存泄漏警告。

在我的演示应用程序中,执行此操作时不会发生对象分配。 方法是空的。 我在 Instruments 中读到的所有内容都与 Foundation 和 Run Loop 相关。 我已经检查了我的类两次并删除了所有对象分配。 它只是一个只显示图像的骨架,但是当触摸它或在屏幕上移动手指时,该图像不会改变。 这是没有意义的。

还有其他人遇到过这样的问题吗?

更新:我进行了更多测试,发现当用 5 个手指快速点击时,内存泄漏会发生在屏幕上的任何位置。 我从 Instruments.app 获得的所有内容都与一些运行和事件循环有关。 似乎设备无法足够快地处理触摸,然后在释放分配的对象时陷入困境。 请尝试一下,如果您发现相同的问题,请在此处报告。

更新:我现在也测试了一些Apple示例应用程序。 当我像普通用户一样用 3 - 5 个手指在屏幕上进行操作时(是的,他们会这样做!),然后 Instrument 会显示有关事件和运行循环的内存泄漏。 框架或乐器中肯定有很大的东西。 使用 iPhone OS 2.2.1 进行测试。

It's really strange. I have a blank UIImageView subclass that implements the -touchesEnded:, -touchesMoved, and -touchesBegan: methods. The implementations of these methods are empty. They just do nothing. However, when I run Instruments with "Leaks", and I touch the UIImageView and move my finger outside of that UIImageView while still touching the screen, I get an Memory Leak warning from Instruments.

In my demo app there's no object allocation happening when doing that. The methods are empty. Everything I read in Instruments is related to Foundation and Run Loop stuff. I've checked my class twice and removed any object allocation. It's just an skelleton that only shows an image, but that image is not changed when touching it or moving the finger on the screen. That makes no sense.

Did anyone else encounter problems like this?

UPDATE: I testet a little more around and figured out, that memory leaks happen at any spot on the screen when tapping fast around with 5 fingers. Everything I get from Instruments.app is regarding some run and event loops. It seems like if the device can't handle the touches fast enough and then gets stuck at some point with releasing allocated objects. Please try it out and report here if you can see the same problems.

UPDATE: I've tested now a few Apple example apps as well. When I hack with 3 - 5 fingers around on the screen, like a normal user does (yes, they will do!), then Instrument shows up memory leaks regarding event and run loops. Definitely there's a big in the framework, or in instruments. Tested with iPhone OS 2.2.1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请远离我 2024-07-29 11:47:20

在苹果论坛上看到,这是SDK中一个未解决的问题。 当加速度计委托不为零时会发生这种情况。 触摸事件对象已分配但从未释放。 调用加速计委托的速度越快,分配失败发生的速度就越快。 许多苹果示例代码都显示了同样的问题。 我打开了加速计。

但我也遇到过,当从一个视图跟踪到另一个视图时,会发生这种泄漏。 如果我不断触摸一个相同的视图并将手指移到该视图上而不离开它,我就不会遇到这个问题。

解决方案:关闭加速计(委托设置为零),减少应用程序中的视图量。 我不知道他们是否在 iPhone OS 3.0 中解决了这个问题。

不幸的是,这不会有帮助:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIAccelerometer sharedAccelerometer] setDelegate:nil]; // because of framework bug
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIAccelerometer sharedAccelerometer] setDelegate:self]; // because of framework bug
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIAccelerometer sharedAccelerometer] setDelegate:self]; // because of framework bug
}

更多信息请访问:http://discussions.apple.com /thread.jspa?messageID=9396584t

As reading on an apple forum, it's an unsolved problem in the SDK. It happens when the accelerometer delegate is not nil. Touch event objects are allocated but never freed. The faster the accelerometer delegate is called, the faster those allocation failures happen. Many of the apple sample codes show the same problem. I had the accelerometer turned on.

But I also encountered, that this kind of leaks happen when a touch is tracked from one view onto another. If I keep touching one and the same view and moving my finger on that view without leaving it, I'll not get that problem.

Solutions: Turn accelerometer off (delegate set to nil), reduce the amount of views in your app. I don't know if they fixed that issue in iPhone OS 3.0.

Unfortunately, this will not help:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIAccelerometer sharedAccelerometer] setDelegate:nil]; // because of framework bug
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIAccelerometer sharedAccelerometer] setDelegate:self]; // because of framework bug
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [[UIAccelerometer sharedAccelerometer] setDelegate:self]; // because of framework bug
}

More info at: http://discussions.apple.com/thread.jspa?messageID=9396584t

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文