mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Add document teardown operation to safely remove rooting for DOM tree and prevent leaks.
This commit is contained in:
parent
818d29d13a
commit
982dd0c0f0
3 changed files with 15 additions and 13 deletions
|
@ -34,18 +34,6 @@ pub fn Document(root: AbstractNode, window: Option<@mut Window>) -> @mut Documen
|
||||||
doc
|
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 {
|
pub impl Document {
|
||||||
fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
|
fn getElementsByTagName(&self, tag: DOMString) -> Option<@mut HTMLCollection> {
|
||||||
let mut elements = ~[];
|
let mut elements = ~[];
|
||||||
|
@ -67,5 +55,14 @@ pub impl Document {
|
||||||
window.content_changed()
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,10 @@ impl ScriptContext {
|
||||||
|
|
||||||
/// Handles a request to exit the script task and shut down layout.
|
/// Handles a request to exit the script task and shut down layout.
|
||||||
fn handle_exit_msg(&mut self) {
|
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)
|
self.layout_task.send(layout_task::ExitMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,8 @@ var count = 1000000;
|
||||||
var start = new Date();
|
var start = new Date();
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
div.setAttribute('id', 'styled');
|
div.setAttribute('id', 'styled');
|
||||||
div.getBoundingClientRect();
|
//div.getBoundingClientRect();
|
||||||
}
|
}
|
||||||
var stop = new Date();
|
var stop = new Date();
|
||||||
window.alert((stop - start) / count * 1e6);
|
window.alert((stop - start) / count * 1e6);
|
||||||
|
window.close();
|
Loading…
Add table
Add a link
Reference in a new issue