Don't leak aux data

This commit is contained in:
Brian Anderson 2012-08-20 17:52:12 -07:00
parent b6fdc4cc2c
commit 517504e4fc
4 changed files with 26 additions and 18 deletions

View file

@ -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);
}

View file

@ -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();

View file

@ -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); }

View file

@ -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,7 +89,8 @@ impl Node : StylePriv {
"]
// TODO: we should look into folding this into building the dom,
// instead of doing a linear sweep afterwards.
fn initialize_style() {
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),
@ -97,23 +98,30 @@ impl Node : StylePriv {
});
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="