3

I'm currently working on a legacy MFC application and I noticed that there was a missing call to GdiplusShutdown() before exiting the application. The documentation clearly states that each GdiplusStartup call must be paired by a call to GdiplusShutdown().

What happens if this function is not called ? Object leak, memory leak, other ?

rold2007
  • 1,297
  • 1
  • 12
  • 25
  • gdi32.dll is a bit special, very global thing (like window handles). so I think it might be possible to leak GDI resources. assuming gdi+ uses gdi internally. – Cheers and hth. - Alf May 10 '15 at 23:49
  • There are no consequences, the OS always brooms up any litter you leave behind. Except one, you won't be able to get a reliable leak report from a diagnostic tool that shows you what *other* resource leaks you have. The kind that makes your app crash when your user uses it longer than you did when you tested it. But of course, if you'd have used one then you would have easily discovered the oversight. You ought to use one. – Hans Passant May 11 '15 at 00:04

1 Answers1

2

The most likely result is that you won't be able to restart GDI+. I.e. you may very well get WrongState if you call GdiplusStartup for the second time without an intervening shutdown. But since you plan to exit the application, this is not a real problem.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • So basically you're saying that the documentation is wrong when it says that GdiplusShutdown **must** be called before exiting the application, which makes this API call totally useless. – rold2007 May 15 '15 at 22:45
  • @rold2007: No, the API call makes sense. E.g. an application which only needs to show UI from time to time should shut down GDI+ in the mean time. But that's rare. – MSalters May 16 '15 at 13:03