2015 Update
In 2012, this was not possible if you wanted to support all major browsers in use. Unfortunately, this is still only a Chrome feature (non-standard extension window.performance ).
window.performance.memory
Browser Support: Chrome 6+
Answer 2012
Is there a way to find out how much memory is being used by a web page or my jquery application? I am looking for a solution for execution (and not just tools for developers) so that my application can determine actions based on memory usage in a user browser.
The simple but correct answer is no . Not all browsers provide you with such data. And I think that you should abandon this idea simply because the complexity and inaccuracy of the “manual” solution can cause more problems than it solves.
Counting DOM elements or document size can be a good estimate, but it can be pretty inaccurate because it will not include event binding, data (), plugins, and other in-memory data structures.
If you really want to stick to your idea, you need to separate fixed and dynamic content.
Fixed content does not depend on user actions (memory used by script files, plugins, etc.)
Everything else is considered dynamic and should be your main focus in determining your limit.
But there is no easy way to generalize them. You can implement a tracking system that collects all this information. All operations must invoke the appropriate tracking methods. eg:
Wrap or rewrite the jQuery.data method to tell the tracking system about your data distributions.
Wrap html manipulations to track the addition or removal of content ( innerHTML.length is the best estimate).
If you store large objects in memory, they should also be tracked.
Regarding event binding, you should use event delegation, and then it can be considered a somewhat fixed factor.
Another aspect that makes it difficult to correctly evaluate memory requirements is that different browsers can allocate memory differently (for Javascript objects and DOM elements).