mono/MonoGame — pull request #905 by slygamer (2012-10-24 14:44:27+00:00)
Title: Fixes to Dispose pattern and disposing GL objects

* I believe this addresses all known issues in #883 and #893.
* Fixes the Dispose pattern for many classes. Allows Dispose() to be called multiple times. Dispose() suppresses the finalizer. Finalizer calls Dispose() if the developer forgets.
* Fixes GL object disposal so it copes with the GL context going away, the GraphicsDevice being disposed, and disposal on a worker thread. Dispatches the disposal work to the UI thread, which is then performed during GraphicsDevice.Present().
* Ensure GraphicsDevice.Present() is called consistently amongst platforms.
* Game.EndDraw() now calls Platform.Present().
* Game now disposes Content and GraphicsDeviceManager.
* GraphicsResource.GraphicsDevice is now a WeakReference internally to cope with the GraphicsDevice being garbage collected out of order at shutdown.
* GraphicsResource-derived classes no longer add an event handler to GraphicsDevice.DeviceResetting. This eliminates a strong reference that was preventing objects from being garbage collected. Functionality is replaced with the global list of GraphicsResource objects and GraphicsResource.DoGraphicsDeviceResetting().
* There may be some other small fixes in there that I have omitted to mention.

Tested on Windows and Android.