9

Suppose that I write some JavaScript code that displays the first ten records from a database as table row elements. When the user clicks to load more rows, the table row elements are removed from the page, but are saved in Javascript.

Now, suppose that I have a similar page that displays 100 rows at a time and there are thousands of rows that the user might page thru.

How can I know how much memory is being used when these elements are cached in Javascript?

3
  • It's hard to say exactly. But you're certainly better off deleting the DOM elements completely and only retaining the data within them. This is a much cleaner approach, isn't hard to do, and can be achieved via various frameworks such as Backbone.js. Commented Jun 8, 2012 at 18:48
  • I would imagine that it takes no more memory than it would to have the DOM elements materialized on the page itself and, perhaps, ever so slightly less. (Which is likely less than a "full size" image these days.) Commented Jun 8, 2012 at 18:52
  • Probably slightly less, as Nodes not in DOM don't have parent references, so at least those two pointers will be null. But there are tons of other properties, so IMO it doesn't make much difference anyway. Commented Jun 9, 2021 at 5:16

1 Answer 1

3

Use Chrome's memory profiler : https://developers.google.com/chrome-developer-tools/docs/heap-profiling

It has all the functions you expect for this kind of analysis.

Sign up to request clarification or add additional context in comments.

1 Comment

You can also use Firebug in Firefox, if you prefer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.