Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
Possible memory leak while creating mesh

I am using RealityKit to generate mesh after a particular time interval and adding it as child to the root node. Before creating another mesh I am removing the previously created Entity from parent node also assigning plainCard = nil to it.

Below is the sample code:

import RealityKit
import Combine
import SceneKit

private var sceneEventsUpdateSubscription: Cancellable!
class ViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    let anchor = AnchorEntity(world: [0,0,0])
    let rootEntity:Entity = Entity()
    var plainCard:ModelEntity? = nil
    var pivot = SCNMatrix4MakeTranslation(0.069, 0.155, 0)
    var timer: Timer? = nil
    
    override func viewDidLoad() {
        super.viewDidLoad()
             
        timer = Timer.scheduledTimer(timeInterval: 0.02, target: self, selector: #selector(addARElement), userInfo: nil, repeats: true)
        arView.scene.addAnchor(anchor)
        anchor.addChild(rootEntity)
        self.rootEntity.position = [0,0,-0.5]
    }
    
    @objc func addARElement() {
        plainCard?.removeFromParent()
        plainCard = nil

        plainCard = ModelEntity(mesh: MeshResource.generateBox(width: 0.2, height: 0.11,depth: 0), materials: [UnlitMaterial(color: .red)])
        plainCard?.transform = Transform(matrix: simd_float4x4(pivot))
        rootEntity.addChild(plainCard!)
    }
}

Here is my question:

With this creation of box at particular interval, memory continues to increase, there is significant increase in CPU usage, energy impact is high. After one point the app crashes because of excessive memory usage. What can be going wrong here? Where is the memory leak happening?

enter image description here

After 5 mins of running app: the frame dropped to 30, memory has gone up from previous image and energy impact is very high

a

I tried Xcode's instruments which shows Heap allocation is getting significant spike enter image description here

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda