在 UITesting 期间导致内存警告和崩溃的背景图像
Posted
技术标签:
【中文标题】在 UITesting 期间导致内存警告和崩溃的背景图像【英文标题】:Background Image causing memory warning and crash during UITesting 【发布时间】:2015-12-11 17:29:04 【问题描述】:我有一个简单的 UITest,它在工具栏上点击一个项目 100 次,运行没有背景图像的测试始终通过,但是当我添加背景图像时,我收到内存警告,然后测试失败。我尝试了许多显示图像的解决方案,大多数都导致相同的结果,内存警告随后崩溃。根据苹果文档,我有一个图像集,由三个尺寸为 3X:2304 X 3072、2X:1536 X 2048 和 1X:768 X 1024 的 png 图像组成。如何添加背景图像以免导致内存问题。
UI测试代码:
func testJustNumberOfRolls()
let app = XCUIApplication()
for _ in 1...100
app.toolbars.buttons["Tip2"].tap()
视图控制器:
class TestVC: UIViewController
override func viewDidLoad()
super.viewDidLoad()
if let image = UIImage(named: "feltSized")
self.view.backgroundColor = UIColor(patternImage: image)
测试日志:
11:10:49.317 XCTRunner[6768:2874277] -[TestingUIActual
testJustNumberOfRolls] started activity <XCActivityRecord: 0x1314a5ab0> 2015-12-11 17:10:49 +0000: Wait for app to idle
11:10:49.528 XCTRunner[6768:2874277] Waiting for app quiescence...
11:10:49.529 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:49.529 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:49.530 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:49.531 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:49.535 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.536 XCTRunner[6768:2874320] Got animations reply.
11:10:49.536 XCTRunner[6768:2874320] Animations are not active.
11:10:49.537 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.537 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:49.538 XCTRunner[6768:2874320] Got event loop idle reply.
11:10:49.539 XCTRunner[6768:2874320] Event loop is idle.
11:10:49.538 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:49.540 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:49.541 XCTRunner[6768:2874322] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:49.542 XCTRunner[6768:2874277] App has quiesced.
11:10:49.542 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1314a5ab0> 2015-12-11 17:10:49 +0000: Wait for app to idle (0.225394s)
11:10:49.550 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1314a2970> 2015-12-11 17:10:49 +0000: Find the "Tip2" Button (0.298589s)
11:10:49.553 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x1314abf80> 2015-12-11 17:10:49 +0000: Synthesize event
11:10:49.966 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.967 XCTRunner[6768:2874320] Got event completion.
11:10:49.969 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1314abf80> 2015-12-11 17:10:49 +0000: Synthesize event (0.416638s)
11:10:49.973 XCTRunner[6768:2874320] Got AX notification 4002
11:10:49.988 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x1315415e0> 2015-12-11 17:10:49 +0000: Wait for app to idle
11:10:50.197 XCTRunner[6768:2874277] Waiting for app quiescence...
11:10:50.198 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.198 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.199 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.200 XCTRunner[6768:2874358] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.204 XCTRunner[6768:2874358] Got AX notification 4002
11:10:50.204 XCTRunner[6768:2874358] Got event loop idle reply.
11:10:50.205 XCTRunner[6768:2874358] Event loop is idle.
11:10:50.205 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.206 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.437 XCTRunner[6768:2874358] Got AX notification 4002
11:10:50.438 XCTRunner[6768:2874358] Got animations reply.
11:10:50.442 XCTRunner[6768:2874358] Animations are not active.
11:10:50.443 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.444 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.446 XCTRunner[6768:2874277] App has quiesced.
11:10:50.447 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x1315415e0> 2015-12-11 17:10:49 +0000: Wait for app to idle (0.459272s)
11:10:50.460 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x13149e5f0> 2015-12-11 17:10:49 +0000: Tap "Tip2" Button (1.4335s)
11:10:50.464 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x1314af0f0> 2015-12-11 17:10:50 +0000: Tap "Tip2" Button
11:10:50.466 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] started activity <XCActivityRecord: 0x131544810> 2015-12-11 17:10:50 +0000: Wait for app to idle
11:10:50.669 XCTRunner[6768:2874277] Waiting for app quiescence...
11:10:50.669 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.670 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.670 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 1 -> 0
11:10:50.671 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 1 -> 0
11:10:50.676 XCTRunner[6768:2874356] Got AX notification 4002
11:10:50.676 XCTRunner[6768:2874356] Got animations reply.
11:10:50.677 XCTRunner[6768:2874356] Animations are not active.
11:10:50.677 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.677 XCTRunner[6768:2874567] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.679 XCTRunner[6768:2874320] Got AX notification 4002
11:10:50.679 XCTRunner[6768:2874320] Got event loop idle reply.
11:10:50.680 XCTRunner[6768:2874320] Event loop is idle.
11:10:50.680 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> hasReceivedAnimationsHaveFinished 0 -> 1
11:10:50.681 XCTRunner[6768:2874357] <XCUIApplicationProcess: 0x12fe466a0 mikepland.crapsBuzzInSwift (6775)> event loop is idle 0 -> 1
11:10:50.682 XCTRunner[6768:2874277] App has quiesced.
11:10:50.682 XCTRunner[6768:2874277] -[TestingUIActual testJustNumberOfRolls] finished activity <XCActivityRecord: 0x131544810> 2015-12-11 17:10:50 +0000: Wait for app to idle (0.216641s)
11:10:50.718 Xcode[1265:207640] Test operation failure: Lost connection to test manager service.
11:10:50.719 Xcode[1265:207640] _finishWithError:Error Domain=IDETestOperationsObserverErrorDomain Code=4 "Lost connection to test manager service." UserInfo=NSLocalizedDescription=Lost connection to test manager service. didCancel: 1
【问题讨论】:
【参考方案1】:更新:我尝试不显示任何图像,这似乎更好。错误显示在“失去与测试管理器服务的连接”。
此时我已经重构了我的应用程序以避免长时间的动画以避免我的测试需要超时,然后重新编码应用程序以隐藏所有图像和背景颜色。即使这样,错误仍然会出现,尽管测试能够运行更长时间。
我能够在一个全新的应用程序上进行复制,只需一个背景图案和一个按钮,即使运行测试超过几分钟也会导致错误,这就是一个全新的应用程序。所以想知道还能做什么,希望这会很快得到解决。
【讨论】:
如果您的答案不起作用,您应该删除它或至少不接受它,并使用必要的信息更新您的问题。谢谢!以上是关于在 UITesting 期间导致内存警告和崩溃的背景图像的主要内容,如果未能解决你的问题,请参考以下文章
CGDataProviderCopyData 在内存中堆积导致崩溃
iOS4 调用 ImageNamed:仍然泄漏或导致内存问题?
在 C# 中进行大量、快速和频繁的内存分配期间避免 OutOfMemoryException