* Pen.cs: Added a note on Dispose method.
authorRavindra <ravindra@mono-cvs.ximian.com>
Tue, 1 Jun 2004 05:00:16 +0000 (05:00 -0000)
committerRavindra <ravindra@mono-cvs.ximian.com>
Tue, 1 Jun 2004 05:00:16 +0000 (05:00 -0000)
* Brush.cs: Fixed Dispose method.
* SolidBrush.cs: Fixed Dispose method.

svn path=/trunk/mcs/; revision=28607

mcs/class/System.Drawing/System.Drawing/Brush.cs
mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Pen.cs
mcs/class/System.Drawing/System.Drawing/SolidBrush.cs

index cf0a32b9cf2b46783eabef82cf59fc054422afcb..e37b2f51c14f665069bb09a6d14e10c80056f285 100755 (executable)
@@ -18,6 +18,7 @@ namespace System.Drawing
        public abstract class Brush : MarshalByRefObject, ICloneable, IDisposable
        {
                internal IntPtr nativeObject;
+               internal bool disposed = false;
                abstract public object Clone ();
 
                 internal Brush ()
@@ -63,8 +64,11 @@ namespace System.Drawing
 
                protected virtual void Dispose (bool disposing)
                {
-                       Status status = GDIPlus.GdipDeleteBrush (nativeObject);
-                       GDIPlus.CheckStatus (status);
+                       if (disposed == false) {
+                               Status status = GDIPlus.GdipDeleteBrush (nativeObject);
+                               GDIPlus.CheckStatus (status);
+                               disposed = true;
+                       }
                }
 
                ~Brush ()
index c17cd3be05e396482215fc4a0f9f881fa18ed059..8d27319a58f60eda79877c9d5e725d19bcedfc75 100644 (file)
@@ -1,3 +1,9 @@
+2004-06-01  Ravindra <rkumar@novell.com>
+
+       * Pen.cs: Added a note on Dispose method.
+       * Brush.cs: Fixed Dispose method.
+       * SolidBrush.cs: Fixed Dispose method.
+
 2004-05-28  Ravindra <rkumar@novell.com>
 
        * gdipFunctions.cs: Added some P/Invoke calls for Draw/Fill
index ffaa8a3696e1901d6b0ce361975a300f0a376281..756663ac3a84446d7a27d1245db60d617340c06b 100755 (executable)
@@ -421,7 +421,9 @@ namespace System.Drawing {
 
                void Dispose (bool disposing)
                {
-                       // Let the GC collect it
+                       // Pen is disposed if and only if it is not disposed and
+                       // it is modifiable OR it is not disposed and it is being
+                       // collected by GC.
                        if ((disposed == false) && (isModifiable || disposing == false)) {
                                Status status = GDIPlus.GdipDeletePen (nativeObject);
                                GDIPlus.CheckStatus (status);
index ffb629b8bfbf7e840e00c87f3dc1b5edc237af0f..81399b3455a6d972b621d627efa89bd3a9cfd201 100644 (file)
@@ -63,10 +63,13 @@ namespace System.Drawing
                
                protected override void Dispose (bool disposing)
                {
-                       // Let the GC collect it
-                       if (isModifiable || disposing == false) {
+                       // SolidBrush is disposed if and only if it is not disposed
+                       // and it is modifiable OR it is not disposed and it is being
+                       // collected by GC.
+                        if ((disposed == false) && (isModifiable || disposing == false)) {
                                Status status = GDIPlus.GdipDeleteBrush (nativeObject);
                                GDIPlus.CheckStatus (status);
+                               disposed = true;
                        }
                        else
                                throw new ArgumentException ("This SolidBrush object can't be modified.");