Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory issue when loading usdz files

I'm loading a .usdz file into my ARSCNView and so far it works fine, except from the fact that when I load multiple objects into my scene the app crashes with message: Terminated due to memory issue.

I'm using Apple's default .usdz samples (https://developer.apple.com/augmented-reality/quick-look/) and the robot file is around 13.5MB big.

It works with up to 4-5 instances and then crashes.

Is the limit for ARKit application so small, or am I doing something wrong?

Here's my code:

// My touch point on the screen
let touchLocation = sender.location(in: sceneView)    

// We have a touch point on an ARPlane
if let result = self.sceneView.hitTest(touchLocation, types: ARHitTestResult.ResultType.existingPlaneUsingExtent).last {

    let position = SCNVector3Make(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)

    // Load the .usdz model        
    guard let usdzURL = Bundle.main.url(forResource: "toy_robot_vintage", withExtension: "usdz") else {
        return
    }

    // Create a node, set position and scale
    let referenceNode = SCNReferenceNode(url: usdzURL)!
    referenceNode.load()
    referenceNode.position = position
    referenceNode.scale = SCNVector3Make(0.01, 0.01, 0.01)

    // Add node to scene
    sceneView.scene.rootNode.addChildNode(referenceNode)
}
like image 226
Pikebu Avatar asked Jan 17 '26 07:01

Pikebu


1 Answers

There's a certain amount of memory an app can allocate and if it exceeds, it's automatically killed by the OS. I tested a simple ARKit app on an iPhone 6S, adding a single usdz file with around 13.5MB of size adds around 280MB to the app's memory usage and the memory limit for the app is 1.37GB as shown in Xcode's Memory Report section:

enter image description here

You can see how memory usage increases each time the same usdz file is added to the scene again. So technically you cannot (and probably shouldn't) add more than a couple of usdz files at the same time to your app.

like image 102
M Reza Avatar answered Jan 19 '26 19:01

M Reza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!