0

Can one cause problems by prematurely releasing a Windows GDI object? With memory one can prematurely delete/free a buffer and cause very serious problems indeed. How about GDI? Can one cause a crash or UI painting issues by prematurely releasing a GDI object?

Radim Cernej
  • 875
  • 1
  • 10
  • 21

1 Answers1

1

You can't delete a GDI object that is currently selected into any device context (DC): https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject

After you delete an object, its handle is invalid, so you can't select it into DC.

What other scenario do you have in mind?

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27
  • Thank you. I did not have any specific scenario in mind, I was just curious if that is a realistic danger that one must watch out for. I am debugging a 20y old program written by others, I am still learning where GDI objects are allocated and released in this program. – Radim Cernej Sep 09 '20 at 23:53