What is the best way to clear the textureCache in A-Frame's latest release?

Currently working on a project involving multi-camera streaming, I've noticed a continuous increase in memory usage after switching between cameras. I've managed to clean up on the hls.js side of things, but I haven't come across any methods to do the same in a-frame. I'm currently using version 1.2.0.

After searching, I found some older posts suggesting to use

document.querySelector('a-scene').systems.material.textureCache
and execute .dispose()

It seems like this method worked on version 0.3.0, but not in the latest versions. Is there a new way to clean up textures or does this now happen automatically?

Answer №1

From my understanding, the textureCache is responsible for managing loaded textures (image, video) as promises.

Although there is a clearTextureCache function, it only clears the object without disposing of the loaded textures.

One approach could be to iterate through the textureCache, retrieve the THREE.Texture objects, and call .dispose() on them. Following this, you can use clearTextureCache() to tidy up. The code snippet below demonstrates how to print cached textures to the console upon window click:

<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script>
  AFRAME.registerComponent("foo", {
    init: function() {
      window.addEventListener("click", e => {
        const textureCache = this.el.systems.material.textureCache;
        console.log("Textures in the cache:")
        for (let key in textureCache) {
          textureCache[key].then(val => console.log(val))
        }
      })
    }
  })
</script>
<a-scene foo>
  <a-image position="-1 1.6 -2" src="https://i.imgur.com/wjobVTN.jpeg"></a-image>
  <a-image position="1 1.6 -2" src="https://i.imgur.com/AD3MbBi.jpg"></a-image>
  <a-sky color="#ECECEC"></a-sky>
</a-scene>

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

What could be causing my second ajax call to render the page unresponsive?

I am encountering an issue with my AJAX call. It works fine on the first attempt, but when I try to call it a second time, the page becomes unresponsive. I am not sure what is causing this issue. The code is located within the document ready function. The ...

update/renew angularjs unique directive

Incorporating the carousel plugin from Ionic Market into my ionic project has been a game changer. This specific plugin, known as Morph Carousel, is a custom AngularJS directive that allows me to display content in a visually appealing way. One unique as ...

Manipulate the value of the <input> element when focused through JavaScript

After I focus on the input field, I was expecting to see Bond-Patterson, but instead, I am only getting Bond. What could be causing this discrepancy and how can it be fixed? $('input[name="surname"]').attr("onfocus", "this.placeholder='Bo ...

Exploring the Concept of Event Bubbling in ReactJS

Having recently delved into React.js, I've encountered a roadblock that has persisted for the past three days despite my attempts at various solutions. The issue revolves around two functions in my parent component named checkout: handleSeleteAddress ...

Is it possible to directly update the label text in AngularJS from the view itself?

I found the following code snippet in my HTML <span ng-class="newProvider ? 'newProvider' : ''" class="help-block"> {{ 'new-product.provider.helper' | locate }} </span> Whenever newProvider is se ...

Using the TypeScript compiler API to determine the location in the generated code of a particular AST node

I am aiming to retrieve the specific TypeScript AST node's location (start and end) in the emitted JavaScript file. Consider this code snippet: const program = ts.createProgram(tsconfig.fileNames, tsconfig.options); const aNode = program.getSourceFi ...

Incorporate a personalized style into the wysihtml5 text editor

Is there a way for me to insert a button that applies a custom class of my choice? I haven't been able to find this feature in the documentation, even though it's a commonly requested one. Here's an example of what I'm looking for: If ...

Creating dynamic div elements using jQuery

I used a foreach loop in jQuery to create some divs. Everything seems to be working fine, but for some reason, my divs are missing SOME class properties. Here is the code snippet I am using: $("#item-container").append("<div class=\"panel col-md-2 ...

Rotate your camera automatically in threejs - let it spin and

I am trying to implement auto-rotation for the camera in my threejs project when it hits any obstacle. I came across a helpful link at where the rendering restarts upon hitting an obstacle. Despite attempting to integrate this feature into my project, it ...

I encounter an error in my JavaScript function indicating that it is not defined

let element = document.querySelector("#value"); let buttons = document.querySelectorAll(".btn"); buttons.forEach(function (button) { button.addEventListener("click", function(event){ console.log(event.currentTarge ...

Tips for deactivating a single edit button

Is there a way to make it so that when I click on a checkbox, only that specific todo's edit button is disabled? Currently, clicking on a checkbox disables all edit buttons in the todo list. Any suggestions? class App extends Component { state ...

Retrieve worldwide data for the entire application in Next.js during the first page load

Within my Next.js application, I am implementing search filters that consist of checkboxes. To display these checkboxes, I need to retrieve all possible options from the API. Since these filters are utilized on multiple pages, it is important to fetch the ...

Swapping out a sequence of characters in a web address with a different set

Swapping out imgur for filmot, Enter URL - https://i.stack.imgur.com/Uguvn.jpg Click the submit button After clicking submit, a new tab should open with the link .filmot.com/abcde.jpg. <html> <head> <title>input</title> <sc ...

Sending information across React context

I've encountered a challenge when trying to transfer data from one context to another in React. The job data I receive from a SignalR connection needs to be passed to a specific job context, but I'm unsure of the best approach for achieving this. ...

Is it possible to execute "green arrow" unit tests directly with Mocha in IntelliJ IDEA, even when Karma and Mocha are both installed?

My unit tests are set up using Karma and Mocha. The reason I use Karma is because some of the functionality being tested requires a web browser, even if it's just a fake headless one. However, most of my code can be run in either a browser or Node.js. ...

What prompts JQuery to interpret ajax responses as xml in Firefox?

let url = "/MyApp/pspace/filter"; let data = JSON.stringify(myData); $.post( url, data, function(response, textStatus, jqXHR) { console.log("response: " + response); }, "json" ); In actuality, the expected type of response is a JSON string. ...

The index.js file in ReactJs is failing to run completely

A couple of months back, I delved into the world of React but eventually put it on hold. Today, I decided to pick it back up and took the following steps: npm init npm install npm start Everything seemed to run smoothly (No Errors), but strangely nothing ...

Utilizing jQuery to Detect TAB Key Press in Textbox

I need to detect when the TAB key is pressed, prevent the default action from occurring, and then execute my custom JavaScript function. ...

Utilizing the $.ajax method along with the onreadystatechange event

Is there a way to use the onreadystatechange event of the underlying XMLHttpRequest in JQuery's (version 2.0.2) $.ajax(...) function to trigger synchronous ajax requests for displaying accurate status indications during long-running processes? It seem ...

The output display is not visible

I am currently working on a tutorial to showcase contact details on my webpage. However, I am facing an issue where the code is not displaying the first and last name as expected. Below is the code snippet for reference. Snippet from index.html <!DOCT ...