/** * Removes all nodes of {@code scope} using DFS. We don't lock here. * * @param scope the parent scope of which all children will recursively be removed * from the map. We don't do anything else to the children nodes are they will be * garbage collected soon. We just cut a whole sub-graph in the references graph of the JVM * normally. */ private static void removeScopeAndChildrenFromMap(ScopeNode scope) { MAP_KEY_TO_SCOPE.remove(scope.getName()); scope.close(); for (ScopeNode childScope : scope.childrenScopes.values()) { removeScopeAndChildrenFromMap(childScope); } }
/** * Detach a scope from its parent, this will trigger the garbage collection of this scope and it's * sub-scopes * if they are not referenced outside of Toothpick. * * @param name the name of the scope to close. */ public static void closeScope(Object name) { //we remove the scope first, so that other threads don't see it, and see the next snapshot of the tree ScopeNode scope = (ScopeNode) MAP_KEY_TO_SCOPE.remove(name); if (scope != null) { ScopeNode parentScope = scope.getParentScope(); if (parentScope != null) { parentScope.removeChild(scope); } else { ConfigurationHolder.configuration.onScopeForestReset(); } removeScopeAndChildrenFromMap(scope); } }
/** * Removes all nodes of {@code scope} using DFS. We don't lock here. * * @param scope the parent scope of which all children will recursively be removed * from the map. We don't do anything else to the children nodes are they will be * garbage collected soon. We just cut a whole sub-graph in the references graph of the JVM * normally. */ private static void removeScopeAndChildrenFromMap(ScopeNode scope) { MAP_KEY_TO_SCOPE.remove(scope.getName()); scope.close(); for (ScopeNode childScope : scope.childrenScopes.values()) { removeScopeAndChildrenFromMap(childScope); } }
/** * Detach a scope from its parent, this will trigger the garbage collection of this scope and it's * sub-scopes * if they are not referenced outside of Toothpick. * * @param name the name of the scope to close. */ public static void closeScope(Object name) { //we remove the scope first, so that other threads don't see it, and see the next snapshot of the tree ScopeNode scope = (ScopeNode) MAP_KEY_TO_SCOPE.remove(name); if (scope != null) { ScopeNode parentScope = scope.getParentScope(); if (parentScope != null) { parentScope.removeChild(scope); } else { ConfigurationHolder.configuration.onScopeForestReset(); } removeScopeAndChildrenFromMap(scope); } }