Clear unused view nodes

Hi,

I use custom layouts. I want to clear the scene from unused viewers (vtkMRMLSliceNode and vtkMRMLViewNode) (and the nodes that are associated to them (as far as i have seen: a vtkMRMLSliceCompositeNode, a vtkMRMLModelDisplayNode, vtkMRMLLinearTransformNode, and a vtkMRMLModelNode in case of a vtkMRMLSliceNode and a vtkMRMLCameraNode in case of a vtkMRMLViewNode)).
How would I do that? Is there a way do detect ‘unused’ view nodes? Best would be to initially prevent the scene/application from generating the default views.
Any hint is appreciated. Thanks

You can use MappedInLayout attribute name, which is set to 0 for views that are not mapped in current layout.