Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out how much memory is allocated to a javascript object? [duplicate]

Possible Duplicate:
JavaScript object size
How to measure memory usage and efficiency?

I guess the answer is probably "You can't", but is there any way to see how much memory is allocated to each object in the DOM/javascript environment? What tools are there and does it vary from browser to browser?

If the answer is indeed "You can't" can anyone explain why not?

like image 508
wheresrhys Avatar asked Apr 24 '12 13:04

wheresrhys


People also ask

How is JavaScript object stored in memory?

Memory spaces in V8 “Variables in JavaScript (and most other programming languages) are stored in two places: stack and heap.

How much memory does a variable take in JavaScript?

How many bytes is a JavaScript object? 64 bits are 8 bytes, but each number actually takes up an average of 9.7 bytes. Likewise, Chrome shows the size of each individual empty array as 32 bytes and the size of each empty object as 56 bytes.

Where is memory stored in JavaScript?

JavaScript engines have two places where they can store data: The memory heap and stack. Heaps and stacks are two data structures that the engine uses for different purposes.


1 Answers

Using Chrome, you can use their developer tools (CTRL + SHIFT + I or F12). Click on the Profiles tab and press the eyeball icon in the status bar.

My versions of Safari and IE8 also have profiling tools, but for CPU only, not memory usage.

like image 65
Lee Kowalkowski Avatar answered Sep 24 '22 02:09

Lee Kowalkowski