GC the RuleTree when the Stylist is dropped.

We only consider doing a GC currently if the root node has a zero refcount.
But that only happens if it has no children -- even weak children keep a
strong reference to their parent.  So at the very least, we should do a
GC specifically when the RuleTree is going away.  (We probably want to add
some other GC opportunities too at some point, otherwise it's easy to
never GC a RuleTree.)
This commit is contained in:
Cameron McCormack 2016-11-18 16:59:24 +08:00
parent dd611ef310
commit 48aa7070ac

View file

@ -624,6 +624,18 @@ impl Stylist {
}
}
impl Drop for Stylist {
fn drop(&mut self) {
// This is the last chance to GC the rule tree. If we have dropped all
// strong rule node references before the Stylist is dropped, then this
// will cause the rule tree to be destroyed correctly. If we haven't
// dropped all strong rule node references before now, then we will
// leak them, since there will be no way to call gc() on the rule tree
// after this point.
unsafe { self.rule_tree.gc(); }
}
}
/// Map that contains the CSS rules for a specific PseudoElement
/// (or lack of PseudoElement).