v169 three.js GLTFLoader does not free Safari memory.
HTML
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/"
}
}
</script>
JavaScript
import * as THREE from "three"
const scene = new THREE.Scene()
const camera = new THREE.PerspectiveCamera(
75,
window.innerWidth / window.innerHeight,
0.1,
1000,
)
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
const geometry = new THREE.BoxGeometry(1, 1, 1)
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 })
const cube = new THREE.Mesh(geometry, material)
scene.add(cube)
import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"
setInterval(function () {
const loader = new GLTFLoader().setPath(
"https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/",
)
loader.load("DamagedHelmet.gltf", async function (gltf) {
//console.log(scene);
if (scene.children[1] !== undefined) {
scene.children[1].children[0].material.dispose()
scene.children[1].children[0].geometry.dispose()
scene.children[1].children[0].removeFromParent()
scene.children[1].removeFromParent()
}
const model = gltf.scene
scene.add(model)
})
}, 2000)
camera.position.z = 5
function animate() {
renderer.render(scene, camera)
}
renderer.setAnimationLoop(animate)