Why am I leaking memory by Array.join? [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
The memory of this line of code will go up about 100 megabytes, and does not get freed:
var json = new Array(100000000).join(",");
Why?

As reported in this answer, each element of your array will take up nearly a byte. 100,000,000 bytes is roughly 95MB. The memory reserved for the array will not be released until the garbage collector runs, which is when it deems fit.
As stated in the MDN:
Most memory management issues come at this phase. The hardest task here is to find when "the allocated memory is not needed any longer". It often requires the developer to determine where in the program such piece of memory is not needed anymore and free it.
So the memory will be released when the browser determines it is no longer needed, or when the developer explicitly states that it is no longer needed (demonstrated elsewhere on that page).

Related

What is the time complexity of JavaScript methods? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Is there any resource to know the time complexity of natively defined array and string methods in JavaScript?
I have to do guess work while I am using them to solve algorithm, but I want to be sure about what is the time complexity of those functions?
This question has been answered previously:
Time Complexity for Javascript Methods in V8
In short, it's not specified and the time complexity for common JS methods can differ between browsers.
Worse yet, some methods might not even exist or will behave differently between different browsers and browser versions!

Any good programming practices/tools to reduce memory fragmentation in JS? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I was noticing very high usage of memory in Firefox, and I saw pages like Gmail and another heavy web-app I was working on, were >100mb! Looking through and seeing some high "unused-gc-things" in about:memory, I found this bug has been reported here and here and is a common problem without a good solution :(
Is there a good tool for detecting arenas of un-garbage-collectable objects short of compiling a special build of Firefox or other browser? And are there better methodologies of writing web-apps that don't use much memory? I would imagine using ArrayBuffer or asm.js may be more efficient as it has one set memory pool, but that doesn't play well with the usual DOM-based interaction and javascript function-al "class"-based programming of most web-apps.

Screeps: Why does the Memory tab no longer update? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
The memory seems to still be reading and writing correctly, but the memory tab always shows the initial state, as though there were no creeps or spawns in the room. It wasn't like this a couple days ago. What do I do? The problem exists in Firefox and Chrome, seemingly regardless of cached data.
Thanks, it is fixed now.
Please keep in mind that it is better to send bugs to contact#screeps.com rather than to post them on StackOverflow, which is for coding questions.
You can click the `refresh' button to the left in order to see the contents of the memory. But I agree that this is a less then optimal way to do things.
Possibly it's an issue with localStorage, artch has answered a similar question about these type of issues: https://stackoverflow.com/a/27060388/1814415
You could try to run the game on another browser or maybe clearing the cache on your current browser.

How To Make Effective Use Of GPU For A Heavy JavaScript Application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Because of the complicated application that I'm building, the JavaScript is pretty huge. Some of the widgets are also quite heavy when it comes to mobile website terms.
Can we transfer the load of some selected widgets, which we feel is heavy, to the GPU to decrease the execution time of the widget?
A very short answer: No.
A longer answer: a) Javascript is a single-threaded system, and b) you don't have access to the hardware at that level.
If you have something that's time consuming that can be offloaded to a background thread you could use a WebWorker to handle that portion of the processing. Note that Webworkers don't have access to the window object, so you can't update the screen with them.
There's an introduction to WebWorkers here and a more complete reference at MDN here

JavaScript distributed computing project [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I made a website that does absolutely nothing, and I've proven to myself that people like to stay there - I've already logged 11+ hours worth of cumulative time on the page.
My question is whether it would be possible (or practical) to use the website as a distributed computing site.
My first impulse was to find out if there were any JavaScript distributed computing projects already active, so that I could put a piece of code on the page and be done. Unfortunately, all I could find was a big list of websites that thought it might be a cool idea.
I'm thinking that I might want to start with something like integer factorization - in this case, RSA numbers. It would be easy for the server to check if an answer was correct (simply test for modulus equals zero), and also easy to implement.
Is my idea feasible? Is there already a project out there that I can use?
Take a look at http://www.igvita.com/2009/03/03/collaborative-map-reduce-in-the-browser/ and http://www.igvita.com/2009/03/07/collaborative-swarm-computing-notes/

Categories

Resources