From 48aa7070acc303e7befe4975fa6dfb1836763b9e Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 18 Nov 2016 16:59:24 +0800 Subject: [PATCH] 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.) --- components/style/stylist.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/style/stylist.rs b/components/style/stylist.rs index de106e7a3de..83bce4bec58 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -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).