Add document teardown operation to safely remove rooting for DOM tree and prevent leaks.

This commit is contained in:
Josh Matthews 2013-05-22 14:14:33 -04:00
parent 818d29d13a
commit 982dd0c0f0
3 changed files with 15 additions and 13 deletions

View file

@ -34,18 +34,6 @@ pub fn Document(root: AbstractNode, window: Option<@mut Window>) -> @mut Documen
doc
}
#[unsafe_destructor]
impl Drop for Document {
fn finalize(&self) {
let compartment = global_script_context().js_compartment;
do self.root.with_base |base| {
assert!(base.wrapper.get_wrapper().is_not_null());
let rootable = base.wrapper.get_rootable();
JS_RemoveObjectRoot(compartment.cx.ptr, rootable);
}
}
}
pub impl Document {
fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
let mut elements = ~[];
@ -67,5 +55,14 @@ pub impl Document {
window.content_changed()
}
}
fn teardown(&self) {
let compartment = global_script_context().js_compartment;
do self.root.with_base |node| {
assert!(node.wrapper.get_wrapper().is_not_null());
let rootable = node.wrapper.get_rootable();
JS_RemoveObjectRoot(compartment.cx.ptr, rootable);
}
}
}

View file

@ -285,6 +285,10 @@ impl ScriptContext {
/// Handles a request to exit the script task and shut down layout.
fn handle_exit_msg(&mut self) {
self.join_layout();
for self.root_frame.each |frame| {
frame.document.teardown();
}
self.layout_task.send(layout_task::ExitMsg)
}

View file

@ -5,7 +5,8 @@ var count = 1000000;
var start = new Date();
for (var i = 0; i < count; i++) {
div.setAttribute('id', 'styled');
div.getBoundingClientRect();
//div.getBoundingClientRect();
}
var stop = new Date();
window.alert((stop - start) / count * 1e6);
window.close();