Memory leak when using UI Automation tests

I am running into a memory issue when running my UI automated tests with XCTestCase in iOS 9. When I launch my UI tests I see two processes get kicked off in xcode, one for the app I am testing and one for the actual UI tests. My app's memory stays around 60 MB, but the UI test grows to around 400 MB before the device kills it for using too much memory. My UI test is pretty simple, where I am just tapping buttons as I go through a test in my app. All of the code looks similar to this, though I go through about 30 questions:


app.buttons["next question button"].tap() // Move to the next question
app.staticTexts["Correct answer text"].tap() // Select the correct answer


At first I thougth that maybe it was how I was doing asserts, since I was using waitForExpectationsWithTimeout. But taking these out doesn't seem to have any effect. It's seems like as my UI updates (and my app UI is going through a lot of views, it is a VERY visual testing app) the XCUIElementQuery items may be keeping track of the entire UI history. So, as my app creates new elements the RAM usage of the UI test skyrockets. See below for an example of what I am seeing in XCode:


Does anyone know of anyway to reset/release this memory? Reinitializing let app = XCUIApplication() doesn't seem to do anything. Or does this seem like a memory leak in the UI automation framework?

Answered by Engineer in 58288022

Please file a bug report (using the Report Bugs link at the bottom of this page). Thanks!

Accepted Answer

Please file a bug report (using the Report Bugs link at the bottom of this page). Thanks!

Bug filed: 22800382

Thanks!

I had a simliar situation where I was doing actions in a loop. About 10 times through the loop (of two taps) it would crash due to high memory usage.


I have worked around my issue by wrapping the loop body in an autoreleasepool block. The UI testing is allocating a huge amount of memory and it _seems_ it is autoreleasing it, which doesn't happen until the test completes, so the autoreleasepool block forces it to release earlier. It seems to be working nicely for me!

Make sure you don't have zombies enabled for the test, that's what my issue appeared to be.

Did you solve this issue?
I also faced this same issue
my ui testing consuming over 270GB on simulator....

Memory leak when using UI Automation tests
 
 
Q