diff --git a/src/servo/dom/rcu.rs b/src/servo/dom/rcu.rs index 9a81c92423f..08f8bfb7827 100644 --- a/src/servo/dom/rcu.rs +++ b/src/servo/dom/rcu.rs @@ -116,9 +116,6 @@ impl Handle { **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); } diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index deb9c19391e..8d44c345c91 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -29,6 +29,10 @@ enum Msg { fn LayoutTask(render_task: RenderTask, image_cache_task: ImageCacheTask) -> LayoutTask { do spawn_listener::|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(); diff --git a/src/servo/layout/style/apply.rs b/src/servo/layout/style/apply.rs index 191cb81e67e..7a104cace09 100644 --- a/src/servo/layout/style/apply.rs +++ b/src/servo/layout/style/apply.rs @@ -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); } diff --git a/src/servo/layout/style/style.rs b/src/servo/layout/style/style.rs index 183e96eebe7..f48b4833802 100644 --- a/src/servo/layout/style/style.rs +++ b/src/servo/layout/style/style.rs @@ -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); } 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="