Gdi+ Memory Leak >Scrolling text
-
Hey Guys a few days ago i made a custom control that uses GDI+. after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on... Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ScreenerViewer.BL.NewsBar;
namespace ScreenerViewer
{public partial class NewsBar : Control { //timer Timer t = new Timer(); //position the text int Position; //normall mode text StringWriter SdisplayNormalMode = null; //Flicker Mode Text StringWriter SdisplayFlickerMode = null; //Separate the Text string sSeparatesign = " \* "; //Use it for Rest Position bool bRestPosition = false; // Backround Color For NormalMode Brush Backroundbrush = Brushes.Red; //Backround Color For Normal mode Brush BackroundFlickBrush = Brushes.Yellow; //Font color for flickermode Brush FontFlickerBrush =Brushes.Red; //counter for color change in flicker mode int iColorChange = 0; //first run of bar bool bFirstRun = false; Font TextFont = new Font(new FontFamily("arial"), 60); //Drawing the Point of the text PointF TextPoint = new PointF(); private bool \_bFilckerMode; public bool bFilckerMode { get { return \_bFilckerMode; } set { \_bFilckerMode = value; } } public NewsBar() { InitializeComponent(); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); SdisplayNormalMode = new StringWriter(); t.Interval = 10; t.Enabled = true; t.Tick += new EventHandler(t\_Tick); Position = 0; bFirstRun = true; } void t\_Tick(object sender, EventArgs e) { Position+=2; Invalidate(); // Update(); } protected override void OnPaint(PaintEventArgs pe) { if (!this.bFilckerMode) { //NormalMode pe.Graphics.FillRectangle(Backroundbrus
-
Hey Guys a few days ago i made a custom control that uses GDI+. after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on... Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ScreenerViewer.BL.NewsBar;
namespace ScreenerViewer
{public partial class NewsBar : Control { //timer Timer t = new Timer(); //position the text int Position; //normall mode text StringWriter SdisplayNormalMode = null; //Flicker Mode Text StringWriter SdisplayFlickerMode = null; //Separate the Text string sSeparatesign = " \* "; //Use it for Rest Position bool bRestPosition = false; // Backround Color For NormalMode Brush Backroundbrush = Brushes.Red; //Backround Color For Normal mode Brush BackroundFlickBrush = Brushes.Yellow; //Font color for flickermode Brush FontFlickerBrush =Brushes.Red; //counter for color change in flicker mode int iColorChange = 0; //first run of bar bool bFirstRun = false; Font TextFont = new Font(new FontFamily("arial"), 60); //Drawing the Point of the text PointF TextPoint = new PointF(); private bool \_bFilckerMode; public bool bFilckerMode { get { return \_bFilckerMode; } set { \_bFilckerMode = value; } } public NewsBar() { InitializeComponent(); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); SdisplayNormalMode = new StringWriter(); t.Interval = 10; t.Enabled = true; t.Tick += new EventHandler(t\_Tick); Position = 0; bFirstRun = true; } void t\_Tick(object sender, EventArgs e) { Position+=2; Invalidate(); // Update(); } protected override void OnPaint(PaintEventArgs pe) { if (!this.bFilckerMode) { //NormalMode pe.Graphics.FillRectangle(Backroundbrus
michael@cohen wrote:
after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on...
michael@cohen wrote:
t.Interval = 10;
Do the math. 100 repaints a second! 15 frames a second will be more than enough.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
michael@cohen wrote:
after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work and Memory Keep Leaking ... after that the text is moving very slow and so on...
michael@cohen wrote:
t.Interval = 10;
Do the math. 100 repaints a second! 15 frames a second will be more than enough.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)I can't beleive you rabbited through all that code or did the interval issues jump out!
Never underestimate the power of human stupidity RAH
-
I can't beleive you rabbited through all that code or did the interval issues jump out!
Never underestimate the power of human stupidity RAH
-
Mycroft Holmes wrote:
did the interval issues jump out!
Mostly, did do a quick scan to see if he was wasting resources, but that was not the case.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)thanx for checking the code. ill try to do as you say...