mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Don't leak aux data
This commit is contained in:
parent
b6fdc4cc2c
commit
517504e4fc
4 changed files with 26 additions and 18 deletions
|
@ -116,9 +116,6 @@ impl<T:send,A> Handle<T,A> {
|
|||
**Warning:** the reader is responsible for keeping this data live!
|
||||
")]
|
||||
fn set_aux(p: @A) unsafe {
|
||||
let p2 = p;
|
||||
unsafe::forget(p2); // Bump the reference count.
|
||||
|
||||
(**self).read_aux = ptr::addr_of(*p);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ enum Msg {
|
|||
|
||||
fn LayoutTask(render_task: RenderTask, image_cache_task: ImageCacheTask) -> LayoutTask {
|
||||
do spawn_listener::<Msg>|request| {
|
||||
|
||||
// This just keeps our dom aux objects alive
|
||||
let mut layout_data_refs = ~[];
|
||||
|
||||
loop {
|
||||
match request.recv() {
|
||||
PingMsg(ping_channel) => ping_channel.send(content_task::PongMsg),
|
||||
|
@ -41,7 +45,7 @@ fn LayoutTask(render_task: RenderTask, image_cache_task: ImageCacheTask) -> Layo
|
|||
node.dump();
|
||||
|
||||
do util::time::time(~"layout") {
|
||||
node.initialize_style_for_subtree();
|
||||
layout_data_refs += node.initialize_style_for_subtree();
|
||||
node.recompute_style_for_subtree(styles);
|
||||
|
||||
let this_box = node.construct_boxes();
|
||||
|
|
|
@ -164,7 +164,6 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(reason = "leaks memory")]
|
||||
fn test_percent_height() {
|
||||
let scope = NodeScope();
|
||||
|
||||
|
@ -178,7 +177,7 @@ mod test {
|
|||
scope.add_child(parent, child2);
|
||||
scope.add_child(child, g1);
|
||||
scope.add_child(child, g2);
|
||||
parent.initialize_style_for_subtree();
|
||||
let _handles = parent.initialize_style_for_subtree();
|
||||
|
||||
do parent.aux |aux| { aux.specified_style.height = some(Px(100.0)); }
|
||||
do child.aux |aux| { aux.specified_style.height = some(Auto); }
|
||||
|
|
|
@ -75,7 +75,7 @@ fn empty_style_for_node_kind(kind: NodeKind) -> SpecifiedStyle {
|
|||
}
|
||||
|
||||
trait StylePriv {
|
||||
fn initialize_style();
|
||||
fn initialize_style() -> ~[@LayoutData];
|
||||
}
|
||||
|
||||
impl Node : StylePriv {
|
||||
|
@ -89,31 +89,39 @@ impl Node : StylePriv {
|
|||
"]
|
||||
// TODO: we should look into folding this into building the dom,
|
||||
// instead of doing a linear sweep afterwards.
|
||||
fn initialize_style() {
|
||||
let node_kind = self.read(|n| copy *n.kind);
|
||||
let the_layout_data = @LayoutData({
|
||||
mut specified_style : ~empty_style_for_node_kind(node_kind),
|
||||
mut box : none
|
||||
});
|
||||
fn initialize_style() -> ~[@LayoutData] {
|
||||
if !self.has_aux() {
|
||||
let node_kind = self.read(|n| copy *n.kind);
|
||||
let the_layout_data = @LayoutData({
|
||||
mut specified_style : ~empty_style_for_node_kind(node_kind),
|
||||
mut box : none
|
||||
});
|
||||
|
||||
self.set_aux(the_layout_data);
|
||||
self.set_aux(the_layout_data);
|
||||
|
||||
~[the_layout_data]
|
||||
} else {
|
||||
~[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait StyleMethods {
|
||||
fn initialize_style_for_subtree();
|
||||
fn initialize_style_for_subtree() -> ~[@LayoutData];
|
||||
fn get_specified_style() -> SpecifiedStyle;
|
||||
fn recompute_style_for_subtree(styles : arc<Stylesheet>);
|
||||
}
|
||||
|
||||
impl Node : StyleMethods {
|
||||
#[doc="Sequentially initialize the nodes' auxilliary data so they can be updated in parallel."]
|
||||
fn initialize_style_for_subtree() {
|
||||
self.initialize_style();
|
||||
fn initialize_style_for_subtree() -> ~[@LayoutData] {
|
||||
let mut handles = self.initialize_style();
|
||||
|
||||
for NTree.each_child(self) |kid| {
|
||||
kid.initialize_style_for_subtree();
|
||||
handles += kid.initialize_style_for_subtree();
|
||||
}
|
||||
|
||||
return handles;
|
||||
}
|
||||
|
||||
#[doc="
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue