PDA

View Full Version : can someone help me on these questions?



garylee
06-13-2006, 09:40 PM
How is garbage collection handled in Javascript?

What are the ways you can deal with x-browser issues? What are the pros and cons of each?


Thank you,
Gary

mwinter
06-13-2006, 10:56 PM
How is garbage collection handled in Javascript?It is automatic. When all references to an object are severed (by assigning null to referring variables, for example), the object is marked for collection. Reclaimation may not be prompt, though.

There are known memory leaks. MSIE has a well-known, and well-documented, COM-related leak that occurs when a circular reference involves a COM object (ActiveX objects and DOM nodes). Other browsers will no doubt have their own leaks, but IE's is typically more serious as it's easy to induce.


What are the ways you can deal with x-browser issues? What are the pros and cons of each?That's a vague and open-ended question. Most cross-browser issues revolve around the host's object model, especially the document object model (DOM). Sticking to the interfaces defined by the W3C can help mitigate against some problems, but it's almost always necessary to write code explicitly for IE. In such cases, though, use feature detection, not browser detection to determine the code path.

Feature detection is a (roughly) one-to-one examination of the objects and methods provided by the host. Very few (if any) assumptions should be made from the implementation of one feature towards another. Certainly, any time you see something like



if (document.getElementById) {
and then notice subsequent code using all manner of other W3C DOM-defined methods, you've found an example of how not to feature detect.

Mike