You can close a view by calling
view.close(), but to do so you need to already have the
view that you want to close.
If you want to close all views that have a specific name, you would do something like:
for view in window.views():
if view.name() == "something":
You can also use
view.id() == someInteger if you happen to know the ID values of the views that you want to close.
If you're going to have a lot of temporary views associated with the same thing that you'd like to close all at once, presumably you don't want them to all have the same
name() or you won't be able to tell them apart when you're working with them.
In such a case, when you create the views you could also do something like the following to tag a view as one that you created:
"magic_setting" is some string that you would create to uniquely identify views you're creating (so namespace it like
"pluginname.magic_setting" or something), and the value can be either a simple
bool as here or some other value that also describes the view.
Later on you can use
view.settings().has("magic_setting") to see if a view has the setting, or
view.settings().get("magic_setting") if you want to get at the value and do something specific.