PDA

View Full Version : memory usage of xml documents in javascript


mrChris
11-12-2003, 11:35 AM
I'm using msxml in a fairly large/complicated web applicaiton (not bragging just that the browser is already doing/storing a lot of stuff - also not worried about cross-platform/browser) to read xml files, but have a concern about memory usage.

we have configuration information on the server (not sensitive) in xml format and quite frequently I will need to look at that information and pull out 3 or 4 fields based on a code.

parsing it everytime I want it is out, so I have 2 options.

1)we're running jsp so I can have a java class cache the file and recent results and respond to requests for information (pros: less memory on client needed, cons : trip to the server each time).

2)parse the file once and keep it, refer to it each time I need to (but could add a client side cache to track recent requests for speed).

my worry is that if this config file gets really big that I'm permanently storing the xmldom that I'm going to put too much pressure on the browser and it'll come crashing down.

does anyone know how to find out how much memory an object is using ? or a rough way of estimating (e.g. nr. elements & nr. attributes * 3.27 ! ).

Thanks

Chris

liorean
11-13-2003, 09:54 PM
Well, not really. You know, as long as the object has a certain set of qualities, how those are achieved and what other qualities are added is not regulated in any way. For example, Mozilla's Rhino engine (using Java) is more memory expensive than SpiderMonkey (using C). In JScript and JScript.NET you can see the same kind of difference, even though those are both C/C++ engines. In JavaScript, it's the ends, not the means, that are important. (And that is also one of the general differences between dynamic languages (which are often interpreted) and static languages (which are often compiled)).

So, no you can't effectively determine the memory consumption. You can use SAX/XPath tools or XML/Hierarchical databases instead of the DOM to ensure that you only use a minimum of memory, however.