Added reference counting and deferred deletion for GDI objects.