Solution
The
Error -12: Out of Memory error occurs because Windows 7 exceeded the maximum number of GDI Handles. This can happen when your UI has too many GDI Objects (Bitmaps, Brushes, Fonts, etc.) opened which are identified in OS by GDI Handles. There is per-process limit of 10,000 GDI Handles defined by default.
To check how many GDI Objects you have in particular process, go to
Windows Task Manager»Processes»View»Select Columns and check GDI Objects. Then you will be able to see the number of GDI Objects for particular process in the GDI Objects column. If the number of GDI Objects is close to 10,000, you will not be able to create other graphical items without receiving
Error -12: Out of Memory.

There are two ways to resolve this issue:
1. Redesign your application to reduce the number of GDI resources.
2. Increase the GDI Handles limit via registry value up to 65,536 (64k).