Obviously this won't work for people who need high-end graphics, but for people like me who don't it should be a solid temporary workaround.
I have a 2011 MBP with this problem. I do heavy compiles regularly so I hit this problem often. The problem probably isn't any third party software (I install almost nothing besides Xcode by default) - the problem seems to be with the discrete graphics card. If you are using the integrated graphics the problem won't happen. Turning off graphics switching won't stop this problem - if you turn that off the discrete card will always be used. There is no Apple-provided way to force integrated graphics all of the time. You have to use a program like "gfxCardStatus" to force integrated graphics. I haven't hit the problem since I did that.