only close all if there are any to close

avoids unnecessary gc on matplotlib < 1.4

closes #5795