In an MFC application with tabbed documents there will always stay 10 GDI font handles if you closed the only tab and opened a new document. It will only allocate those 10 handles if it is the first tab that is opened.
We discovered this error because we have to open and close very many documents sequentially. When we reach about the 950th iteration of opening and closing the only tab the gdi handle count reaches 10000 and the application raises a CResourceException.
Currently we are using a workaround to prevent this from happening. We open one empty document, then do our tasks and close this empty document afterwards.