What I am showing is not technically a crash, but to users of SOLIDWORKS the result is the same.
GDI objects are used to draw window elements that are not in the graphics area in SolidWorks. For maximum performance the Graphics area takes advantage of OpenGL which gives more direct access to the video processing hardware. GDI objects are used for the chrome of the graphics area, so every time a new document is opened the number of GDI objects used by SOLIDWORKS will increase. Prior so SOLIDWORKS 2011 SP4 if a part was open in an assembly and its own window when that window was closed it would not release those GDI objects. The default behaviour now is to release those handles, however not all of them are released.
What does all this have to do with SOLIDWORKS crashing? Windows has a default limit that a single process can only access 10,000 GDI objects. Since SolidWorks does not release all objects when a document is closed that number it uses continuously increases with each new document opened.
Can this be used to predict when SOLIDWORKS will crash?
Predicting a SOLIDWORKS Crash
As mentioned earlier this is not technically a crash, if SOLIDWORKS reaches the 10,000 object limit windows terminates the process. This is not caused by unhandled code error or memory sharing issues or anything else that causes a crash. This is simply windows saying SOLIDWORKS is being too much of a resource hog and closes it to get those resources back. But since there is a specific number at which it closes if you can monitor that number you can predict when it will happen. As it turns out it is actually very easy to monitor. Simply follow these steps:
- Open task manager (you can right click on the task bar and click task manager)
- Click View, Select Columns…
- Check off GDI Objects and click OK
- Now the task manager will show the current number of GDI Objects being used by each process
If a part is opened and closed several times the number of GDI objects it uses does not increase. SOLIDWORKS releases all handles every time. The same applies to assemblies as well. The problem is only encountered when a part is open in an assembly and it is opened in its own window and then closed. Here is a table of a session I recorded on my computer:
|No docs open|
|Part open 1|
|Part closed 1|
|Part open 2|
|Part closed 2|
|Part open 3|
|Part closed 3|
|Part open 4|
|Part closed 4|
|Part open 5|
|Part closed 5|
|Part open 6|
|Part closed 6|
|Part open 7|
|Part closed 7|
When I originally opened SOLIDWORKS it used 939 objects with no documents open. After opening and closing a part several times with an assembly open and then closing all documents it still used 1401 objects. Over a long period of time this could reach the 10,000 mark, especially if you open the top level assembly.
Avoiding this crash problem
How can this problem be avoided? Do not keep your assemblies open unless you need them to be, and monitor your task manager periodically to see how many objects you are using. Closing SOLIDWORKS and opening it will reset this count. Furthermore you can increase the maximum number of GDI Objects a process can use by following these settings:
- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\GDIProcessHandleQuota (range: 256 ~ 65,536)
- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\USERProcessHandleQuota (range: 200 ~ 18,000)
For additional information, please visit the following websites for a description on how these settings affect a computer:
- GDIProcessHandleQuota: http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx
- USERProcessHandleQuota: http://msdn.microsoft.com/en-us/library/ms725486(VS.85).aspx