Skip to content
Browse files

Playing around with GC and disposal of objects.

  • Loading branch information...
1 parent 9482b1e commit 6b4ce8b656a02056a0f2ce9d53e72bc7c09e258c @Cheesebaron committed Jul 4, 2012
View
30 MonoDroid.ColorPickers/AlphaPatternDrawable.cs
@@ -81,27 +81,29 @@ private void GeneratePatternBitmap()
}
_bitmap = Bitmap.CreateBitmap(Bounds.Width(), Bounds.Height(), Bitmap.Config.Argb8888);
- var canvas = new Canvas(_bitmap);
- var r = new Rect();
- var verticalStartWhite = true;
- for (var i = 0; i <= _numRectanglesVertical; i++)
+ using (var canvas = new Canvas(_bitmap))
{
- var isWhite = verticalStartWhite;
- for (var j = 0; j <= _numRectanglesHorizontal; j++)
+ var r = new Rect();
+ var verticalStartWhite = true;
+ for (var i = 0; i <= _numRectanglesVertical; i++)
{
+ var isWhite = verticalStartWhite;
+ for (var j = 0; j <= _numRectanglesHorizontal; j++)
+ {
- r.Top = i * _rectangleSize;
- r.Left = j * _rectangleSize;
- r.Bottom = r.Top + _rectangleSize;
- r.Right = r.Left + _rectangleSize;
+ r.Top = i * _rectangleSize;
+ r.Left = j * _rectangleSize;
+ r.Bottom = r.Top + _rectangleSize;
+ r.Right = r.Left + _rectangleSize;
- canvas.DrawRect(r, isWhite ? _paintWhite : _paintGray);
+ canvas.DrawRect(r, isWhite ? _paintWhite : _paintGray);
- isWhite = !isWhite;
- }
+ isWhite = !isWhite;
+ }
- verticalStartWhite = !verticalStartWhite;
+ verticalStartWhite = !verticalStartWhite;
+ }
}
}
View
1 MonoDroid.ColorPickers/ColorPickerDialog.cs
@@ -113,6 +113,7 @@ public void OnClick(View v)
ColorChanged(this, new ColorChangedEventArgs { Color = _oldColor.Color });
break;
}
+ GC.Collect();
Dismiss();
}
View
14 MonoDroid.ColorPickers/ColorPickerView.cs
@@ -303,8 +303,8 @@ protected override void OnDraw(Canvas canvas)
DrawAlphaPanel(canvas);
}
- private void DrawSatValPanel(Canvas canvas){
-
+ private void DrawSatValPanel(Canvas canvas)
+ {
var rect = _satValRect;
if(BorderWidthPx > 0){
@@ -334,7 +334,6 @@ protected override void OnDraw(Canvas canvas)
_satValTrackerPaint.Color = Color.Argb(255, 221, 221, 221);
canvas.DrawCircle(p.X, p.Y, _paletteCircleTrackerRadius, _satValTrackerPaint);
-
}
private Point SatValToPoint(float sat, float val)
@@ -367,9 +366,9 @@ private void DrawHuePanel(Canvas canvas)
}
if (_hueShader == null) {
- _hueShader =
- new LinearGradient(rect.Left, rect.Top, rect.Left, rect.Bottom, BuildHueColorArray(), null, Shader.TileMode.Clamp);
- _huePaint.SetShader(_hueShader);
+ using(_hueShader =
+ new LinearGradient(rect.Left, rect.Top, rect.Left, rect.Bottom, BuildHueColorArray(), null, Shader.TileMode.Clamp))
+ _huePaint.SetShader(_hueShader);
}
canvas.DrawRect(rect, _huePaint);
@@ -629,6 +628,7 @@ public override bool OnTouchEvent(MotionEvent e)
case MotionEventActions.Up:
_startTouchPoint = null;
update = MoveTrackersIfNeeded(e);
+ GC.Collect(); //Not sure if collecting too much here...
break;
}
@@ -901,6 +901,8 @@ protected override void Dispose(bool disposing)
}
}
+ GC.Collect();
+
base.Dispose(disposing);
}
}
View
31 MonoDroid.ColorPickers/RoundColorPickerView.cs
@@ -40,12 +40,13 @@ public RoundColorPickerView(Context c, Color color)
new Color(0,255,255,255).ToArgb(), new Color(0,255,0,255).ToArgb(), new Color(255,255,0,255).ToArgb(),
new Color(255,0,0,255).ToArgb()
};
- Shader s = new SweepGradient(0, 0, _colors, null);
-
- _paint = new Paint(PaintFlags.AntiAlias);
- _paint.SetShader(s);
- _paint.SetStyle(Paint.Style.Stroke);
- _paint.StrokeWidth = 32;
+ using (Shader s = new SweepGradient(0, 0, _colors, null))
+ {
+ _paint = new Paint(PaintFlags.AntiAlias);
+ _paint.SetShader(s);
+ _paint.SetStyle(Paint.Style.Stroke);
+ _paint.StrokeWidth = 32;
+ }
_centerPaint = new Paint(PaintFlags.AntiAlias)
{
@@ -172,27 +173,11 @@ public override bool OnTouchEvent(MotionEvent e)
}
_trackingCenter = false; // so we draw w/o halo
Invalidate();
+ GC.Collect();
}
break;
}
return true;
}
-
- protected override void Dispose(bool disposing)
- {
- /*if (disposing)
- {
- if (null != _paint)
- {
- _paint.Dispose();
- }
- if (null != _centerPaint)
- {
- _centerPaint.Dispose();
- }
- }*/
-
- base.Dispose(disposing);
- }
}
}

0 comments on commit 6b4ce8b

Please sign in to comment.
Something went wrong with that request. Please try again.