|
No custom paint handlers.
Been doing some digging on this using sos.dll (just learned how to use it today). What I'm seeing is a heavy accumulation of WeakReference objects (as below).
00415b08 7247 115952 Panasonic.Cumulus.NodeSignature
004a2cc0 21 131492 Free
5c912ee4 1289 164388 System.Int32[]
00265dc8 7959 222852 Panasonic.Navigation.Airport
00416170 6145 294960 Panasonic.Cumulus.Tree.SearchNode
5c910964 40147 481764 System.Object
00266320 33732 1484208 Panasonic.Lists.Vector`1[[System.String, mscorlib]]
5c90a4f8 106481 1703696 System.WeakReference
5c8e4518 43721 1754732 System.Object[]
5c910d48 75853 4065948 System.String
00625b08 6250 100000 Panasonic.Cumulus.NodeSignature
00482cc0 21 132216 Free
5c912ee4 1080 139412 System.Int32[]
00125dc8 7959 222852 Panasonic.Navigation.Airport
00626170 5290 253920 Panasonic.Cumulus.Tree.SearchNode
5c910964 29503 354036 System.Object
00126320 23956 1054064 Panasonic.Lists.Vector`1[[System.String, mscorlib]]
5c90a4f8 70067 1121072 System.WeakReference
5c8e4518 31679 1526020 System.Object[]
5c910d48 70002 3827708 System.String
00625b08 994 15904 Panasonic.Cumulus.NodeSignature
5c912ee4 223 22208 System.Int32[]
00626170 730 35040 Panasonic.Cumulus.Tree.SearchNode
00482cc0 22 131548 Free
00125dc8 7959 222852 Panasonic.Navigation.Airport
5c910964 19523 234276 System.Object
00126320 18547 816068 Panasonic.Lists.Vector`1[[System.String, mscorlib]]
5c8e4518 21952 2319992 System.Object[]
5c90a4f8 170293 2724688 System.WeakReference
5c910d48 58574 3265092 System.String
00625b08 3853 61648 Panasonic.Cumulus.NodeSignature
5c912ee4 698 88716 System.Int32[]
00626170 3184 152832 Panasonic.Cumulus.Tree.SearchNode
5c910964 16087 193044 System.Object
00125dc8 7959 222852 Panasonic.Navigation.Airport
00126320 12652 556688 Panasonic.Lists.Vector`1[[System.String, mscorlib]]
00482cc0 17208 1438032 Free
5c910d48 61646 3463780 System.String
5c8e4518 17493 3603972 System.Object[]
5c90a4f8 334571 5353136 System.WeakReference
00625b08 1227 19632 Panasonic.Cumulus.NodeSignature
5c912ee4 258 27292 System.Int32[]
00626170 933 44784 Panasonic.Cumulus.Tree.SearchNode
00125dc8 7959 222852 Panasonic.Navigation.Airport
5c910964 19907 238884 System.Object
00126320 18727 823988 Panasonic.Lists.Vector`1[[System.String, mscorlib]]
5c910d48 59022 3288024 System.String
5c8e4518 22302 4688996 System.Object[]
00482cc0 34649 5804452 Free
5c90a4f8 562981 9007696 System.WeakReference
I've seen the numerous posts regarding this that suggest you just recompile in Release rather than Debug mode, however that isn't the case here - I can still see the memory climb when I run the app.
I've tried dumping some of the objects and all it seems to point to is a floating system.object:
Scan Thread 3128 OSTHread c38
Scan Thread 5780 OSTHread 1694
Scan Thread 6204 OSTHread 183c
Scan Thread 2680 OSTHread a78
Scan Thread 3232 OSTHread ca0
DOMAIN(007D3988):HANDLE(Pinned):1b13fc:Root:03501010(System.Object[])->
02502074(System.Collections.Generic.List`1[[System.WeakReference, mscorlib]])->
035b0df8(System.Object[])->
02a2fe9c(System.WeakReference)
I was fairly certain I had all the events issues sorted but perhaps not. I'll go through and take a closer look at the difference classes involved (using your shift-f12 suggestion) and see if I can find anything likely.
Thanks for the response.
|
|
|
|
|
Right, found the answer. Thought I'd post how I did it here for anyone else who gets stuck on something like this.
First thing I did was a bunch of reading to school myself on memory leaks in .NET, how they're created, and how to hunt them down. I recommend the following articles:
Best Practices No. 5: Detecting .NET application memory leaks[^]
Memory Leak Detection in .NET[^]
I also downloaded Process Explorer and used that as a general tool to monitor application performance and judge if what I was doing had any useful impact at all.
http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx[^]
It's important to note that before doing any of the above, I had already traced down the sections of code in my program that were creating the link. There are various ways to do this. For me, I had at least a general idea of the method calls causing the problem, so I began systematically commenting out blocks of code and re-running the app while watching Process Explorer. I eventually got to a point where the leak stopped occurring, at which point it became clear to me where this was happening. So lesson 1, it turns out that finding the leak can be pretty easy; fixing it might be not as straight forward.
I used sos.dll to dump my heap memory while running the program to see exactly what it was that was causing the usage to blow up. I'll note here that my platform is Win7 64 bit and my program was configured to target any CPU, which caused issues when I tried to click the "Enable unmanaged code debugging" check box in the project properties window. I had to set the target CPU to x86 to get that to work. Everything else as presented in the article I linked above concerning sos.dll worked as described (I used !dumpheap, !gcroot, etc commands from the immediate window in my case).
What I found was that I had a large number of System.WeakReference instances hanging around and not getting cleaned up. You can see where I discuss this earlier in this thread. From what I've read on the net, it seems that the biggest cause of this happening is when you instantiate object that add event handlers and then don't remove those handlers properly later when you're done with the object. I thought that this wasn't a problem in my code because I had rewritten it to minimize events and handlers as much as possible.
Even so, it turns out that I'm an idiot.
A long time ago, I wrote a generic interface for my class library that describes a basic set of debugging/logging events and handlers for any class that I wanted to be able to write information to my own home-rolled logging system. Very simple stuff; in a nutshell:
Public Interface CoreEvents
Event InfoMessage(ByVal e As EventInfo)
Sub OnInfo(ByVal Message As String)
Sub OnInfo(ByVal e As EventInfo)
Event Err(ByVal e As EventErr)
Sub OnErr(ByVal Description As String)
Sub OnErr(ByVal e As EventErr)
Event Exception(ByVal e As EventBaseException)
Sub OnException(ByVal e As System.Exception)
Sub OnException(ByVal e As EventBaseException)
Event Debug(ByVal e As EventDebug)
Sub OnDebug(ByVal Message As String)
Sub OnDebug(ByVal e As EventDebug)
Event Warning(ByVal e As EventWarning)
Sub OnWarn(ByVal Message As String)
Sub OnWarn(ByVal e As EventWarning)
End Interface
This works out fine when you have a few root classes that implement it that you expect to live throughout the life of the program. But when I wrote this, it worked out so well for me and made my life so easy that it became common practice for my to implement this in any new class I created.
So, I had some very low level items in the object hierarchy (node, signatures, etc, etc) all inheriting from a single master object: SortElement. SortElement is a custom object I wrote that anything can inherit from and become something that can be sorted rapidly in a Vector class that I wrote at some point. Guess what interface SortElement implements? Yep: CoreEvents. Duh.
So I went back and cleaned that up and remove that interface from anything that doesn't need it or shouldn't get it (specifically, objects likely to be instantiated and then dumped on a moment's notice like list nodes or helper classes like NodeSignature.
As an added measure, I also implemented the following pattern in my code for any objects that I wanted to make doubly sure would get sorted out by the GC:
http://msdn.microsoft.com/en-us/library/s9bwddyx%28v=vs.90%29.aspx[^]
I wrapped all that up and rebuilt and was met with an app that consumes no more than 35 MB of memory while running (before it was consuming something like 300 K per second perpetually until running into an OOM exception).
I also find it relevant to note that I did not have to rebuild the application under Release config (rather than Debug) as many forum posts out there suggest (I'm building against .net 3.5).
Anyway, hope some folks find this helpful. I'm actually rather thankful I came across this; it was maddening but well worth what I learned when dealing with it.
|
|
|
|
|
Hi all,
My web application was working perfectly. There was no issue with that.
Suddenly I was need to add a reference of System.Web.Helpers.ddl in my project. After adding this in my project I am getting an error
Cannot implicitly convert type 'System.DateTime' to 'var' on this line var date = DateTime.Now.AddYears(i);
before this it was working perfectly, I didn't made any change in my code.
<pre lang="c#">protected void Bind_Year()
{
try
{
DataTable dt = new DataTable();
dt.Columns.Add("Year", typeof(int));
for (int i = -2; i < 4; i++)
{
var date = DateTime.Now.AddYears(i);
var year = date.Year;
dt.Rows.Add(year);
}
DropDownList3.DataSource = dt;
DropDownList3.DataBind();
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}</pre>
|
|
|
|
|
Perhaps something defines var as something it shouldn't?
Either way, replace var with the actual type, it serves no purpose here.
|
|
|
|
|
This is not the right solution,I have 30 pages where i used this code.
Why I need to change it? although It was working fine before adding the reference.
|
|
|
|
|
Or remove the reference and see if it goes away. Your choice.
|
|
|
|
|
I really hate to tell you this but the size of the problem does not justify whether the solution is "right" or not. If you didn't make a bad coding decision in the first place and use it across 30 pages the solution wouldn't be so big either.
Creating a type called "var" is a bad idea as is naming any of your types after a reserved word in any language. It just leads to ambiguity problems for the compiler (as you've found out) and makes it very difficult to understand the code and debug it.
C# keywords list[^]
|
|
|
|
|
so you mean, I need to change it in all 30 pages? is there no another way to solve it?
|
|
|
|
|
|
It looks like the included reference may have brought in some definition for var . Easy to test, just remove that reference and see if the error goes away. You should also be able to use intellisense to look at the definition of var in your code.
|
|
|
|
|
Yes, very right.
Sorry Sir, the issue has been solved. Actually I don't have any idea that how a class file named var.cs came in my App_Code folder, after adding reference to System.Web.Helpers ddl. Now I have deleted it.
That class file was making problem.
Anyway thanks.. Smile
|
|
|
|
|
Hi, I am opening the UDL file from Browse button in WPF application. After clicking on OK button of UDL wizard connection information should be displayed in WPF application's Datagrid. Please give me any way to do this.
modified 5-Aug-14 1:38am.
|
|
|
|
|
Please don't crosspost. If you Google a bit you'll find the format[^]. You read it in the same way as a textfile, and display it on a form.
Good luck.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi, i have a problem with my WindowsForms Application.
I have a Form with various controls which change size when the user changes the size of the Window. That works and i used Anchor and Dock properties to realize that.
The application has different languages and two buttons to chose the current language which works also with that kind of code:
private void LoadLanguage( string Language)
{
ComponentResourceManager Resources = new ComponentResourceManager(typeof(Form1));
CultureInfo CultureInfo = new CultureInfo(Language);
doRecursiveLoading(this, CultureInfo, Resources);
}
private void doRecursiveLoading(Control Parent, CultureInfo CultureInfo, ComponentResourceManager Resources)
{
foreach(Control c in Parent.Controls)
{
Resources.ApplyResources(c, c.Name, CultureInfo);
if (c.Controls.Count > 0)
doRecursiveLoading(c, CultureInfo, Resources);
}
}
But now i get a problem: My init state is a solution of 1280x1024. When i maximise the window to Fullscreen on HD-Monitor and then click the button for changing the language it changes the language but it also resizes all my controls to the inital size they had at a resolution of 1280x1024 and not the size they should have at fullscreen.
Hope you can understand my problem and some of you has an idea how to fix that.
Thannks in advance.
Chrissi
modified 5-Aug-14 3:35am.
|
|
|
|
|
ChriSSi003 wrote: Hope you can understand my problem and some of you has an idea how to fix that. If "all" controls resize to a max (as opposed to filling the form) while using docking, then there's probably a panel in there that's not docked correctly to "fill".
Take in account that when localizing size and location is localized with it. Often a button becomes larger or smaller due to a different caption, same for labels and the likes. The IDE will put those also in the resource-dll if you are using the IDE to do the translation.
int curlang = 0;
List<string> langs = new List<string>(new [] {"nl-NL", "en-GB", "en-US" });
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ComponentResourceManager Resources = new ComponentResourceManager(typeof(Form1));
CultureInfo CultureInfo = new CultureInfo(langs[curlang]);
Resources.ApplyResources(button1, button1.Name, CultureInfo);
curlang += 1;
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It is likely caused by
Resources.ApplyResources(c, c.Name, CultureInfo);
The resources contain information about the size, and that size is now applied. So I suggest to remove the size and position information from the resources (but then you have to make sure that the controls are well sized for any of the languages supported).
|
|
|
|
|
Can you tell me where to find the information about size?
In my two .resx files for German and English language i dont have any information about size or position.
So i think it has to come out of the ComponentResourceManager thing.
ComponentResourceManager Resources = new ComponentResourceManager(typeof(Form1));
I tried to find information about size in that but it seems so big and complex that i don't know where to look.
Maybe you can help me where to find it.
Thanks in advance.
|
|
|
|
|
What do you need to change with the languages? If it is text only, I'd suggest to set it rather "directly":
c.Text = Resources.GetString(resourceName, CultureInfo);
(resourceName is likely c.Name, but I am not sure with this point).
instead of
Resources.ApplyResources(c, c.Name, CultureInfo);
|
|
|
|
|
Bernhard Hiller wrote: c.Text = Resources.GetString(resourceName, CultureInfo);
Thanks a lot. That works the way I need it.
|
|
|
|
|
So I'm getting my feet wet in .net 3.5 in VS 2008.
Made a form with a button to open another form.
On the called form. I close the form. Simple enough.
I build the exe
I start the program (watch memory usage in task manager),
click the button to open the other form (watch memory in task manager),
then close the form (watch memory in task manager).
Keep repeating. Memory usage just gets larger.
Button click does this: foo_form.show()
Use the window close [X] top right of form.
Looks like memory is leaking.
Don't rememebr vb6 doing this.
Many thanks.
|
|
|
|
|
My guess is that the memory usage hasn't grown enough to trigger the garbage collector.
You could try calling Dispose() on the second window after it closes and see if that has any effect.
You could also try "manually" invoking garbage collection after the second window closes (first setting any references to it to null).
|
|
|
|
|
Thank you. Seem to remember something about garbage collection
being automatic. The environment looks pretty slick. Should
be lots of fun.
|
|
|
|
|
Bret Stern wrote: watch memory in task manager),
There's your first mistake. Task Manager is not showing you how much memory your application is using, but how much the .NET CLR has RESERVED for your application. Use the .NET Memory counters in PerfMon to find out how much memory your app is actually using.
By reserved, I mean your application can free memory that it isn't using any more but that memory goes back the Managed Heap for future allocations. It will not be freed back to Windows unless the CLR deems that it doesn't need the memory or Windows starts to run low on memory and requests that the .NET CLR frees up whatever it can.
The is a completely automatic process and the .NET Memory Manager does it's job very well. You do not need to worry about freeing up the memory yourself.
Next, this depends on what you're using to show the second form. If you use the .ShowDialog() method on your form instance you MUST call Dispose() method on the form instance when you're done with the form. If you don't do this you WILL run into memory and handle issues, possibly running Windows out of resources.
Oh, and do NOT call GC.Collect() unless you know exactly why you're doing it and understand completely the impacts on the GC. You can easily negatively impact the performance of your application by calling Collect unnecessarily.
|
|
|
|
|
Not use to the memory babysitting. Thanks for the explanations.
|
|
|
|
|
I have to track the lists of all the visited urls from any browser like Internet Explorer, Mozilla Firefox, Google Chrome, Opera etc.
To get the all opened tabs in the Internet Explorer, I have used the below codes :
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
string filename;
ArrayList windows = new ArrayList();
foreach (SHDocVw.WebBrowser ie in shellWindows)
{
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
Console.WriteLine("IE Url for '" + ie.LocationName + "' is " + (ie.LocationURL));
}
}
But my question is that how can I get this same all the opened tabs description from other browser?
I have found the below code to get the only one tab which is open in the browser.
using DDE to get the current tab.
private string GetBrowserURL(string browser)
{
try {
DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo");
dde.Connect();
string url = dde.Request("URL", int.MaxValue);
string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries);
dde.Disconnect();
return text[0].Substring(1);
}
catch {
return null;
}
}
I have checked WinPCap, SharpPcap, Pcap but could not get the right solutions to solve the issue.
I need a source code using c# which will be running successfully in .Net 2.0 framework to get the all visited urls lists from all the browser.
Please help me to solve this issue.
|
|
|
|