Managing memory in Three.js

I am facing an issue with managing memory in my large scene that consists of Mesh and MorphAnimMesh objects. I have tried to free up memory by removing these meshes, but it seems like the memory usage remains unchanged.

for ( var i = scene.children.length - 1; i >= 0 ; i -- ) {
  var obj = scene.children[i];
  scene.remove(obj);
  obj.deallocate(); 
  obj.geometry.deallocate();
  obj.material.deallocate();
  obj.material.map.deallocate();
}

Even after setting the object to null, there doesn't seem to be any decrease in memory usage. Google Chrome's memory snapshot shows the objects are still present, particularly mentioning morphTargets in THREE.Geometry @1862203.

I need to find a way to effectively remove objects from memory before transitioning between levels in my game, as the memory usage keeps increasing significantly after multiple level changes.

If anyone has any ideas on what I might be doing wrong or a better approach to manage memory in Three.js, please let me know.

Answer №2

I attempted various dispose and deallocate methods, but none proved successful.

Subsequently, I implemented the following steps for my ionic application that utilizes a webgl renderer for rendering a 360 image.

this.renderer = new THREE.WebGLRenderer({ antialias: true });
RicohView.prototype.stopRendering = function () {
    this.canRender = false;
    this.renderer.forceContextLoss();
    this.renderer.dispose();
    console.log('renderer disposed');
    cancelAnimationFrame(this.requestId);
}

The requestId can be obtained from

this.requestId = requestAnimationFrame(render);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JavaScript function not executing

Within a panel in an UpdatePanel, there is both a dropdown list and a file upload control. The goal is to enable the Upload button when a value is selected from the dropdown and a file is uploaded. This functionality is achieved through a JavaScript functi ...

Is combining form and fieldset causing issues?

My <form> for uploading an image and my <fieldset> for sending data via AJAX both work individually. However, when I try to merge them into one form, things get complicated. This is being done on a Node.JS server. Upload <form>: <for ...

Vue.js Interval Functionality Malfunctioning

I'm brand new to Vuejs and I'm attempting to set an interval for a function, but unfortunately it's not working as expected. Instead, I am encountering the following error: Uncaught TypeError: Cannot read property 'unshift' of u ...

The formValidation, previously known as BootstrapValidator, is causing issues with my form submission via Ajax, despite my efforts to update the code to work with

I recently upgraded the old BootstrapValidator to the new 0.6.0 release known as formValidation. Despite reading the documentation multiple times, I have been unsuccessful in finding the issue and need some assistance. Below are the CSS styles and scripts ...

Why does WebdriverIO send a POST request for an unused webelement?

Exploring the capabilities of webdriverIO has been quite enjoyable! There are many features of this framework that I already appreciate. In my investigation, I wanted to see how WebdriverIO handles non-existing elements and lazy element loading in this te ...

Enabling Multiple Login Feature in Node.js

const handleLogin = async (req, res) => { const User = require("../models/user"); const LoginInfo = require('../models/login_info'); try { const { email, mobile, password, otp } = req.body; const params = []; if(ema ...

A Guide to Dynamically Updating Page Titles Using JavaScript in a Ruby on Rails Application

Every time I use Ajax to load a blog post on the webpage, I adjust the <title> to "My Blog - BLOGPOST_TITLE". It is worth mentioning that "My Blog - " also shows up in the application layout. My dilemma is, how do I inform my Javascript about the " ...

Issue with Jquery Date picker functionality on Master Page not functioning as expected

My issue is with the master page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- ...

Getting the dimensions of an image when clicking on a link

Trying to retrieve width and height of an image from this link. <a id="CloudThumb_id_1" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: 'http://www.example.com/598441_l2.jpg'" onclick="return theFunction();" href="http ...

Combining Rails 4 with coffeescript while encountering an issue with the jQuery sortable detatch functionality

Currently, I am using Ruby on Rails 4 along with the jquery-ui-rails gem. Within my application, there are certain lists that have a sortable jQuery function implemented. $ -> $('#projects').sortable handle: '.handle' ...

Exploring Elasticsearch: Uncovering search results in any scenario

I've been working on a project where my objective is to receive search engine results under all conditions. Even if I enter a keyword that is not included in the search data or if it is an empty string, I still want to get some kind of result. How can ...

Workers in Async.js queue failing to complete tasks

Creating a job queue to execute copy operations using robocopy is achieved with the following code snippet: interface copyProcessReturn { jobId: number, code: number, description: string, params: string[], source: string, target: s ...

Creating unique custom geometry with Autodesk Forge

Currently, I am encountering an issue where rendering custom geometry in my Forge application is consuming a significant amount of memory. I am following the technique recommended on the Autodesk website: . I need to display up to 300 custom geometries in ...

Storing a new field without saving mongoose.Types.ObjectId as a database column in MongoDB

Trying to establish a relationship between two collections in MongoDB. I have a User collection with unique _id for each user, and a News collection where each news item should be linked to a specific user using their userId. In my API workflow, the userI ...

Twice the data fetching through ajax on popup is observed using php mysql

I've been struggling for the past two hours. Attempted : location.reload(); reset form Tried many features, but after closing my popup and reopening it or opening another ID, the previous ID data is still visible. This happens continuously for all ...

Nginx proxy pass interferes with the execution of Javascript within script tags

I currently have a website built with Nuxtjs that is functioning behind an nginx proxy_pass configuration. For instance, the Nuxtjs site can be accessed at , while the main site is located at http://example.com. Below is the nginx configuration for exampl ...

What is the best way to choose the initial p tag from an HTML document encoded as a string?

When retrieving data from a headless CMS, the content is often returned as a string format like this: <div> <p>1st p tag</p> <p>2nd p tag</p> </div> To target and select the first paragraph tag (p), you can extract ...

What are the advantages of utilizing buffer geometries in Three.js?

I have experience using both BufferGeometry and Geometry, so I feel comfortable with either. Even when I need to make frequent modifications, I tend to lean on BufferGeometry because although the code is more verbose, it's not overly complex. Can you ...

Step-by-step guide on incorporating a new JSON object into an array to display its elements as components on a webpage

Could I adjust the state of an array by incorporating values from a data.js file as a starting point? The process involves executing the setAllThingsArray function to add a new element, determined by the setThingsArray function based on the previous state ...

When the PHP response is received by AJAX, an error occurs due to a failed JSON parsing request

Every time I try to run my small JavaScript code with an AJAX call to PHP, it keeps coming back with a JSON parser error. In the PHP code, I can see that the JSON is populated with an array like this: json encode: {"Year":"2012","Make":"Ford","Model":"Tau ...