- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个应用在使用大约 30-35 分钟后会降低整个操作系统的速度。滞后是渐进的,我可以看到它随着时间的推移而累积,因为我一遍又一遍地重复相同的操作。这是一个音乐应用程序,在播放大约 15-20 首轨道后,延迟是无法忍受的。
在 UIScrollView 中滚动项目时,帧率下降到 10 以下。许多帧被跳过,UI 几乎被锁定。如果我为该应用程序设置后台,我会在 SpringBoard 的操作系统中看到这种滞后,而且基本上无处不在。在 SpringBoard 中滚动应用程序图标变得不稳定。滑动解锁变得断断续续等
我将如何着手解决这个问题?可能是什么原因。由于代码库相当复杂,我无法削减代码来创建最小的可重现示例。我需要帮助来了解可能导致操作系统几乎锁定的原因。这不是死锁,因为 UI 仍然有响应,只是需要很长时间。
哪些分析工具可以帮助阐明此问题的原因?我怀疑这可能是因为内存泄漏,但令人惊讶的是,操作系统并未向应用程序发送内存警告,所以我对此也不太确定。
非常感谢任何帮助。
最佳答案
问题出在动画的构建上。事件监视器在调试此问题时最有用。 Springboard 的 CPU 使用率一直在上升,直到达到 100%。所以时间显然不是花在我的应用程序上,而是花在驻留在 Springboard 中的渲染服务器上。
我创建了两个具有大量重复次数的动画,让它们永远运行。然后我将每个动画添加到一个单独的层。为了创建动画,我使用了惰性检查,并向图层询问任何具有给定键的现有动画。如果图层没有返回任何内容,我就创建了动画。问题是该层总是不返回任何内容,所以我一直在创建这些永远重复的动画。
这是有问题的代码。
// This call always returned nil.
CABasicAnimation *innerRotationAnimation = (CABasicAnimation *)[self.spinnerViewInner.layer animationForKey:@"rotationAnimation"];
// So I kept on creating animations and piling them up.
if (innerRotationAnimation == nil)
{
CATransform3D innerRotationTransform = CATransform3DMakeRotation(0.25f * M_PI * -1, 0, 0, 1.0);
innerRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
innerRotationAnimation.toValue = [NSValue valueWithCATransform3D:innerRotationTransform];
innerRotationAnimation.duration = 0.25f;
innerRotationAnimation.cumulative = YES;
innerRotationAnimation.repeatCount = HUGE_VALF;
[self.spinnerViewInner.layer addAnimation:innerRotationAnimation forKey:@"rotationAnimation"];
}
为了解决这个问题,我开始删除现有的动画。我本可以在两个点上完成此操作,要么在 animationDidStop:finished:
回调中,要么在我的 setAnimating:
方法中,两者都运行良好。这是 setAnimating:
方法中的更改。
- (void)setAnimating:(BOOL)animating
{
if (animating == NO) {
// Remove all existing animations now.
[self.layer removeAllAnimations];
}
else {
CABasicAnimation *animation = // Create animation;
[self.layer addAnimation:animation forKey:@"rotationAnimation"];
}
}
如果有人感兴趣,这是原始的BROKEN代码。
- (void)setAnimating:(BOOL)animating
{
if (self.isAnimating == animating)
{
return;
}
_animating = animating;
if (self.isAnimating == YES)
{
CABasicAnimation *innerRotationAnimation = (CABasicAnimation *)[self.spinnerViewInner.layer animationForKey:@"rotationAnimation"];
CABasicAnimation *outerRotationAnimation = (CABasicAnimation *)[self.spinnerViewOuter.layer animationForKey:@"rotationAnimation"];
if (innerRotationAnimation == nil)
{
CATransform3D innerRotationTransform = CATransform3DMakeRotation(0.25f * M_PI * -1, 0, 0, 1.0);
innerRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
innerRotationAnimation.toValue = [NSValue valueWithCATransform3D:innerRotationTransform];
innerRotationAnimation.duration = 0.25f;
innerRotationAnimation.cumulative = YES;
innerRotationAnimation.repeatCount = HUGE_VALF;
[self.spinnerViewInner.layer addAnimation:innerRotationAnimation forKey:@"rotationAnimation"];
}
if (outerRotationAnimation == nil)
{
CATransform3D outerRotationTransform = CATransform3DMakeRotation(0.25f * M_PI * -1, 0, 0, -1.0);
outerRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
outerRotationAnimation.toValue = [NSValue valueWithCATransform3D:outerRotationTransform];
outerRotationAnimation.duration = 0.25f;
outerRotationAnimation.cumulative = YES;
outerRotationAnimation.repeatCount = HUGE_VALF;
[self.spinnerViewOuter.layer addAnimation:outerRotationAnimation forKey:@"rotationAnimation"];
}
}
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
self.spinnerViewInner.layer.opacity = (self.isAnimating ? 1.0 : 0.0);
self.spinnerViewOuter.layer.opacity = (self.isAnimating ? 1.0 : 0.0);
}
有一件事我仍然很好奇。由于给定的键只能有一个事件动画,当我尝试使用相同的键添加一个新动画时,Core Animation 不应该删除我现有的动画吗?为什么 animationForKey:
根本不返回 nil
。
关于objective-c - 长时间使用后应用程序和操作系统滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13501152/
我有一个简单的应用程序,它读取数据库,然后经过一些操作将结果写入另一个数据库。 第一行代码使用给用户的消息和屏幕日志更新 ui,然后全部包装在带有 using 和其他 try/catch 的 try/
我有一个名为activity的表,其中有一个memberId和一个时间戳。我想找出在给定的月份中有多少成员执行了一项 Activity (即-在 Activity 表中有记录),但在过去12个月中,谁
我有前三列数据。第一个列表示 id 在前一天做了某件事。我试图通过添加一个新变量“new”来从 dat 转到 dat2,该变量执行三件事: 将 yest 的值复制到前一天。但日子并不总是连续的。因此,
我有一个简单的应用程序,它读取数据库,然后经过一些操作将结果写入另一个数据库。 第一行代码使用给用户的消息和屏幕日志更新 ui,然后全部包装在带有 using 和其他 try/catch 的 try/
我有 data.frame,它显示了股票的当前出价和要价以及我当时的信号。 time bid_price ask_price signal 10:10:01.000500
我无法让网站正常运行。它有许多移动背景并使用 css-invert 过滤器。 请看这里: http://epicstudios.de/blackwhite/ 我的问题是,即使是普通计算机也无法处理移动
我创建了一个矩形对象网格并将它们添加到一个 Pane 中。每个矩形都有一个连接到它的鼠标事件监听器,它由 MouseEvent.Entered 触发器触发。当用户将鼠标移到矩形上时,处理程序只是更改矩
感觉我的笔记本电脑不允许控制台应用程序以一定的速度运行,因为我也尝试过其他应用程序,并且它们也随机滞后。我的机器不老,也不应该这样做,它具有i7-4720HQ CPU @ 2.60GHz(8 CPUs
我现在正面临这个问题。当我的页面加载 (DOM) 时,我调用一个返回 1880 张图像的函数,这些图像存储在 Steam 服务器中。 这些图像在回调之后被添加到我的 DOM 中,该回调返回我的数组响应
我正在尝试创建一个每两秒执行一次函数的应用程序。为了实现这一点,我使用 Timer.scheduledTimer 函数。问题是该函数没有按照应有的那样每两秒执行一次。通常应用程序开始时的间隔是 2 秒
我得到了这个 gps 接收器方法,它将一些数据存储到数据库中。 // GPS private void addGPSListener() { globalconstant.db
我有一个 UISwitch,它可以在切换值时更改其上方 UILabel 的文本。每隔一段时间(大约 2% 的时间)文本不会改变。标签的文本被保存到文本文件中,因此我需要准确性。由于这个问题是间歇性的,
我有一个包含用户帖子的表格 View 。每个帖子都有图片、用户名和帖子本身。刷新控件的操作是使用来自 Parse 的数据重新加载表。除了拉动刷新时的极度延迟外,一切都完美无缺。不知道是因为每个单元格里
我有一个“详细信息”页面,其中显示俱乐部的信息。该页面是一个 UIViewController,由按钮和标签组成,以实现这种外观(就像分组的小表格)。当我在设备上加载此页面时,它比我的应用程序中的任何
我有 ActionSheet 的代码,它可以连接的东西有点慢? @IBAction func showAction(_ sender: UIButton) { let actionSheetC
我的桌面应用程序滞后。我认为 java.awt.image.BufferStrategy 中有问题。 private void render() { BufferStrategy bs
你好,我有一个包含多个页面的 viewpager(使用 fragment 状态寻呼机),以及一些 png 作为这些页面的背景。我已经遵循了在 Ui 中显示位图 (http://developer.an
我在 WPF 窗体上有一个 richtextbox 控件。它有 SpellChecking.IsEnabled 设置为 true 并且 VerticalScrollBarVisibility 设置为
在我的 android 应用程序中,我将数据存储在本地 SQLite 数据库中。在这个数据库的大小小于 8-9 MB 之前,一切都很顺利;然而,一旦数据库大小约为 9 MB,它就会继续在 logcat
我正在开发一个简单的 Android 应用程序,它只有一个 Activity ,一个 WebView。它在我的手机(Android 7.1.2 Nougat 版本)上运行良好,但我收到许多用户的投诉,
我是一名优秀的程序员,十分优秀!