[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Does anyone know SystemColorTracker

Sascha Füller

1/21/2005 8:46:00 PM

Hello everybody,

does anybody know what System.Drawing.Internal.SystemColorTracker is doing?


The reason I ask this is a strange behavioer I found in my application.
I think I can fix the problem, but the behavior of this component
(SystemColorTracker) seems really confusing.

As I was profiling memoryusage of my application I recognized that over some
time many thousands instances of WeakReference were created (about !! 100000
!! in half an hour, using memory of 1,5MB)
While looking deeper into it I recognized that all these Instances get
created by a call to SystemColorTracker.Add when SolidBrush.set_Color is
called.
I looked into it some deeper with Reflector and looked what this component
does.
- Everytime I set a SystemColor to my SolidBrush.Color-Property, then
SystemColorTracker is called and a WeakReference is created.
(in my application the color is changed many thousand times and so many
thoused WeakReferences to the same object are created)
- But what I find really confusing is that all methods and mempers of
SystemColorTracker are private and only the Add-Method is internal,
and it seems that nobody is here to reuse the WeakReference.
But what can I do with such a "WriteOnly" object?


Thanks in advance
Sascha


2 Answers

Bob Powell

1/22/2005 1:11:00 AM

0

I've never seen this. If you can produce a little bit of code that
demonstrates this problem I'll make sure it's reported to the proper people
within Microsoft.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Sascha Füller" <sascha.fueller@b*deleteme*oschrexroth.de> wrote in message
news:csrpik$2vd$1@online.de...
> Hello everybody,
>
> does anybody know what System.Drawing.Internal.SystemColorTracker is
> doing?
>
>
> The reason I ask this is a strange behavioer I found in my application.
> I think I can fix the problem, but the behavior of this component
> (SystemColorTracker) seems really confusing.
>
> As I was profiling memoryusage of my application I recognized that over
> some time many thousands instances of WeakReference were created (about !!
> 100000 !! in half an hour, using memory of 1,5MB)
> While looking deeper into it I recognized that all these Instances get
> created by a call to SystemColorTracker.Add when SolidBrush.set_Color is
> called.
> I looked into it some deeper with Reflector and looked what this component
> does.
> - Everytime I set a SystemColor to my SolidBrush.Color-Property, then
> SystemColorTracker is called and a WeakReference is created.
> (in my application the color is changed many thousand times and so many
> thoused WeakReferences to the same object are created)
> - But what I find really confusing is that all methods and mempers of
> SystemColorTracker are private and only the Add-Method is internal,
> and it seems that nobody is here to reuse the WeakReference.
> But what can I do with such a "WriteOnly" object?
>
>
> Thanks in advance
> Sascha
>


Sascha Füller

1/22/2005 11:06:00 AM

0

Hello,

I have produced a simple example wich shows the described effect.
by clicking on the button there are done 10000 calls to the described
Function

After three cycles (30000 calls to SystemColorTracker) CLR Profiler shows a
usage of about 700 kByte in WeakReference and WeakReference[]

Also I know that we schould change the design of aur application at this
point, I don't think the Framework schould behave like this.

Kind regards
Sascha



>>> code beginn >>>

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SysteColorTracker
{
public class MainForm : System.Windows.Forms.Form
{
// created once and used many times
private SolidBrush longLivingBrush = new SolidBrush(Color.White);

private System.Windows.Forms.Button button1;
public MainForm()
{
InitializeComponent();
}

[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}

#region Windows Forms Designer generated code
private void InitializeComponent() {
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(224, 32);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.Button1Click);
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.button1);
this.Name = "MainForm";
this.Text = "MainForm";
this.ResumeLayout(false);
}
#endregion

void Button1Click(object sender, System.EventArgs e)
{
// on every change from user-color to SystemColor the SystemColorTracker
add is called
for (int i = 0; i < 10000; i++)
{
longLivingBrush.Color = Color.FromArgb (11, 12, 13);
longLivingBrush.Color = Color.FromKnownColor (KnownColor.ActiveBorder);
}

}

}
}

<<< code end <<<



"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> schrieb im Newsbeitrag
news:OCYdn9BAFHA.1300@TK2MSFTNGP14.phx.gbl...
> I've never seen this. If you can produce a little bit of code that
> demonstrates this problem I'll make sure it's reported to the proper
> people within Microsoft.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Sascha Füller" <sascha.fueller@b*deleteme*oschrexroth.de> wrote in
> message news:csrpik$2vd$1@online.de...
>> Hello everybody,
>>
>> does anybody know what System.Drawing.Internal.SystemColorTracker is
>> doing?
>>
>>
>> The reason I ask this is a strange behavioer I found in my application.
>> I think I can fix the problem, but the behavior of this component
>> (SystemColorTracker) seems really confusing.
>>
>> As I was profiling memoryusage of my application I recognized that over
>> some time many thousands instances of WeakReference were created (about
>> !! 100000 !! in half an hour, using memory of 1,5MB)
>> While looking deeper into it I recognized that all these Instances get
>> created by a call to SystemColorTracker.Add when SolidBrush.set_Color is
>> called.
>> I looked into it some deeper with Reflector and looked what this
>> component does.
>> - Everytime I set a SystemColor to my SolidBrush.Color-Property, then
>> SystemColorTracker is called and a WeakReference is created.
>> (in my application the color is changed many thousand times and so
>> many thoused WeakReferences to the same object are created)
>> - But what I find really confusing is that all methods and mempers of
>> SystemColorTracker are private and only the Add-Method is internal,
>> and it seems that nobody is here to reuse the WeakReference.
>> But what can I do with such a "WriteOnly" object?
>>
>>
>> Thanks in advance
>> Sascha
>>
>
>