App Crashing with message: "Terminated due to memory issue."

My iOS app crashes with this popup:

Message from debugger: Terminated due to memory issue

In the debugger, I occasionally get this message as well: No error handler for XPC error: Connection interrupted

This only happens on a certain iPad Pro (11-inch) and no other devices. It seems to be happening when I am saving data to a file.

Does anyone have an idea of what could be causing this or how I could find out? I also forgot to mention that the iPad Pro (11-inch) is running iOS 15.6. Thanks.

It has run out of memory.

Is the file you are saving very large?

It may mean that is has specifically run out of stack; I'm not sure about that. Infinite recursion is the normal reason for running out of stack.

What does it say when you click on "Details"?

Yes, the file I am saving is very large. I checked through my code and I don't see any place where infinite recursion could be occurring. When I click on "Details," I get this message:

Details



The app “My App Name” on My iPad Pro quit unexpectedly.

Domain: IDEDebugSessionErrorDomain

Code: 10

Failure Reason: Message from debugger: Terminated due to memory issue

User Info: {

    DVTErrorCreationDateKey = "2022-08-11 17:37:42 +0000";

    IDERunOperationFailingWorker = DBGLLDBLauncher;

}

--



Analytics Event: com.apple.dt.IDERunOperationWorkerFinished : {

    "device_isWireless" = 1;

    "device_model" = "iPad8,1";

    "device_osBuild" = "15.6 (19G71)";

    "device_platform" = "com.apple.platform.iphoneos";

    "launchSession_schemeCommand" = Run;

    "launchSession_state" = 2;

    "launchSession_targetArch" = arm64;

    "operation_duration_ms" = 40022;

    "operation_errorCode" = 10;

    "operation_errorDomain" = IDEDebugSessionErrorDomain;

    "operation_errorWorker" = DBGLLDBLauncher;

    "operation_name" = IDEiPhoneRunOperationWorkerGroup;

    "param_consoleMode" = 0;

    "param_debugger_attachToExtensions" = 0;

    "param_debugger_attachToXPC" = 1;

    "param_debugger_type" = 5;

    "param_destination_isProxy" = 0;

    "param_destination_platform" = "com.apple.platform.iphoneos";

    "param_diag_MainThreadChecker_stopOnIssue" = 0;

    "param_diag_MallocStackLogging_enableDuringAttach" = 0;

    "param_diag_MallocStackLogging_enableForXPC" = 1;

    "param_diag_allowLocationSimulation" = 1;

    "param_diag_gpu_frameCapture_enable" = 0;

    "param_diag_gpu_shaderValidation_enable" = 0;

    "param_diag_gpu_validation_enable" = 0;

    "param_diag_memoryGraphOnResourceException" = 0;

    "param_diag_queueDebugging_enable" = 1;

    "param_diag_runtimeProfile_generate" = 0;

    "param_diag_sanitizer_asan_enable" = 0;

    "param_diag_sanitizer_tsan_enable" = 0;

    "param_diag_sanitizer_tsan_stopOnIssue" = 0;

    "param_diag_sanitizer_ubsan_stopOnIssue" = 0;

    "param_diag_showNonLocalizedStrings" = 0;

    "param_diag_viewDebugging_enabled" = 1;

    "param_diag_viewDebugging_insertDylibOnLaunch" = 1;

    "param_install_style" = 0;

    "param_launcher_UID" = 2;

    "param_launcher_allowDeviceSensorReplayData" = 0;

    "param_launcher_kind" = 0;

    "param_launcher_style" = 0;

    "param_launcher_substyle" = 0;

    "param_runnable_appExtensionHostRunMode" = 0;

    "param_runnable_productType" = "com.apple.product-type.application";

    "param_runnable_swiftVersion" = "5.6.1";

    "param_runnable_type" = 2;

    "param_testing_launchedForTesting" = 0;

    "param_testing_suppressSimulatorApp" = 0;

    "param_testing_usingCLI" = 0;

    "sdk_canonicalName" = "iphoneos15.5";

    "sdk_osVersion" = "15.5";

    "sdk_variant" = iphoneos;

}

--





System Information



macOS Version 12.5 (Build 21G72)

Xcode 13.4.1 (20504) (Build 13F100)

Timestamp: 2022-08-11T10:37:42-07:00

the file I am saving is very large.

How large, approximately, and how are you saving it?

The file can be very large, but in the case of the crash it is 226.4 MB. Here is how I save the data:

func encodeFile(data: fileTemplate) -> Data {  // encodes to json

    let rawData:Data = try! JSONEncoder().encode(data)

    return rawData

}


let fileData = // setting struct data to save here


let directoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]

var dataToSave:String = ""

var fileURL:URL!


fileURL = URL(fileURLWithPath: fileName, relativeTo: directoryURL).appendingPathExtension("txt")

print("size: \(fileURL.fileSizeString)")

dataToSave = String(data: encodeFile(data: fileData), encoding: .utf8)!


guard let data = dataToSave.data(using: .utf8) else {

    print("unable to save the data")

    completion?(false)

    return

}

// save the data

do {

    try data.write(to: fileURL!)

    completion?(true)

} catch {

    print("Error3: ", error.localizedDescription)

    completion?(false)

}

I think we need a Swift expert to tell us how many copies of your data will exist at the same time as that code runs.

It's quite possible that there are 3 copies. You may need to think about how to do the writes in a more incremental or streaming style.

Just to clear, in the example you posted fileData.count is 226.4 MB?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

App Crashing with message: "Terminated due to memory issue."
 
 
Q