Why is my C# so big?
-
I have now completed my first real C# program - its a nice system tray thing with a notifier that goes and notifies me when I have new web mail by doing HTTP Post/Gets (these response with an XML reply which I then parse). It also uses the TaskbarNotifier class and the QuickRegistry class that I found in the CodeProject articles (many thanks to the respective authors for these). My only problem is that the release version of the build consumes 14MB of RAM. I compare this with msnim (which Im sure is written with .NET) and other "long running" processes of the same caliber, and I can only come to the conclusion that I need to reduce the running footprint of my program. Next Q: What can I do to reduce the running footprint? I have: * Changed the build type to "Release" * Removed TRACE from the build parameters (under Conditional Compilation Constants) Is there anything else in general I can do, or do I start attempting to rework code at this point to make it lighter weight? (e.g. constant sized strings rather than dynamic strings) -Adrian
-
I have now completed my first real C# program - its a nice system tray thing with a notifier that goes and notifies me when I have new web mail by doing HTTP Post/Gets (these response with an XML reply which I then parse). It also uses the TaskbarNotifier class and the QuickRegistry class that I found in the CodeProject articles (many thanks to the respective authors for these). My only problem is that the release version of the build consumes 14MB of RAM. I compare this with msnim (which Im sure is written with .NET) and other "long running" processes of the same caliber, and I can only come to the conclusion that I need to reduce the running footprint of my program. Next Q: What can I do to reduce the running footprint? I have: * Changed the build type to "Release" * Removed TRACE from the build parameters (under Conditional Compilation Constants) Is there anything else in general I can do, or do I start attempting to rework code at this point to make it lighter weight? (e.g. constant sized strings rather than dynamic strings) -Adrian
Hmmm.. The size of your application looks ok for a .NET Windows Forms application. Unfortunately, this is the price you pay for all those neat features. You can try calling GC.Collect() at strategic points to reduce the memory footprint. Changing your strings won't help. You can try this[^] and try to locate some points for improvement, but don't expect to go lower than 9~10Mb. I see dumb people
-
I have now completed my first real C# program - its a nice system tray thing with a notifier that goes and notifies me when I have new web mail by doing HTTP Post/Gets (these response with an XML reply which I then parse). It also uses the TaskbarNotifier class and the QuickRegistry class that I found in the CodeProject articles (many thanks to the respective authors for these). My only problem is that the release version of the build consumes 14MB of RAM. I compare this with msnim (which Im sure is written with .NET) and other "long running" processes of the same caliber, and I can only come to the conclusion that I need to reduce the running footprint of my program. Next Q: What can I do to reduce the running footprint? I have: * Changed the build type to "Release" * Removed TRACE from the build parameters (under Conditional Compilation Constants) Is there anything else in general I can do, or do I start attempting to rework code at this point to make it lighter weight? (e.g. constant sized strings rather than dynamic strings) -Adrian
-
How are you checking memory usage? I tried Process.WorkingSet and it seemed to keep eating memory. I'm after a more "lite weight" way to check memory usage in my apps
If the WorkingSet directly refers to what you have through the task manager, then don't waste your time with it. You've got to check out the "virtual memory" indicator, which is much more trustable.
-
I have now completed my first real C# program - its a nice system tray thing with a notifier that goes and notifies me when I have new web mail by doing HTTP Post/Gets (these response with an XML reply which I then parse). It also uses the TaskbarNotifier class and the QuickRegistry class that I found in the CodeProject articles (many thanks to the respective authors for these). My only problem is that the release version of the build consumes 14MB of RAM. I compare this with msnim (which Im sure is written with .NET) and other "long running" processes of the same caliber, and I can only come to the conclusion that I need to reduce the running footprint of my program. Next Q: What can I do to reduce the running footprint? I have: * Changed the build type to "Release" * Removed TRACE from the build parameters (under Conditional Compilation Constants) Is there anything else in general I can do, or do I start attempting to rework code at this point to make it lighter weight? (e.g. constant sized strings rather than dynamic strings) -Adrian
I don't beleive that Instant Messenger is written with the .NET Framework, so it's probably not a good comparison. For a managed application, 14MB seems reasonable to me. However, if you want to trim your working set, you might try calling this, which might free up 10MB of code that gets used as part of initialization, but might not be needed to run... Warning: this might not work on Windows 9x. If you've got that in your target configurations, you might want to test for it in Empty below...
using System.Runtime.InteropServices; namespace PutYourNamespaceHere { /// /// Utility class for manipulating working set. /// internal class WorkingSet { /// /// Removes as many pages as possible from the working set of the /// current process. /// internal static void Empty() { SetProcessWorkingSetSize( -1, -1, -1 ); } [ DllImport( "Kernel32", CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)] private static extern bool SetProcessWorkingSetSize( int handle, int min, int max); } }
Burt Harris
-
I don't beleive that Instant Messenger is written with the .NET Framework, so it's probably not a good comparison. For a managed application, 14MB seems reasonable to me. However, if you want to trim your working set, you might try calling this, which might free up 10MB of code that gets used as part of initialization, but might not be needed to run... Warning: this might not work on Windows 9x. If you've got that in your target configurations, you might want to test for it in Empty below...
using System.Runtime.InteropServices; namespace PutYourNamespaceHere { /// /// Utility class for manipulating working set. /// internal class WorkingSet { /// /// Removes as many pages as possible from the working set of the /// current process. /// internal static void Empty() { SetProcessWorkingSetSize( -1, -1, -1 ); } [ DllImport( "Kernel32", CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)] private static extern bool SetProcessWorkingSetSize( int handle, int min, int max); } }
Burt Harris
First, thanks for the cool tip, will try it out in one of my apps. Is there a sane way of knowing the amount of memory consumed by a .net application, for ex. if I have an application A and application B running, the task manager shows a big chunk of memory used by both these apps. I'm almost sure the task manager is wrong. Is it true that the runtime is being shared by these two apps, how do I find out the individual memory consumptions of these two applications. thanks Kannan
-
If the WorkingSet directly refers to what you have through the task manager, then don't waste your time with it. You've got to check out the "virtual memory" indicator, which is much more trustable.
Unfortunately, task manager does not report true memory usage, it reports what it "thinks" an app needs - try it out for yourself load up word or something similar open task manager and find the instance of the program you have just started While task manager is open, minimize the app watch the memory usage drop. I did this with Word and the memory usage in task manager dropped from 14 meg to 500k - somehow I don't think that it's reporting correct memory here. Process.WorkingSet is supposed to report the memory usage used by the enitre app (and any component dll's?) but the last time I used it, my memory usage blew out to 110 meg after 6 - 7 hours, and I think this is what caused the high memory usage - this is why I'm after a more "liteweight" of checking memory usage.
-
Unfortunately, task manager does not report true memory usage, it reports what it "thinks" an app needs - try it out for yourself load up word or something similar open task manager and find the instance of the program you have just started While task manager is open, minimize the app watch the memory usage drop. I did this with Word and the memory usage in task manager dropped from 14 meg to 500k - somehow I don't think that it's reporting correct memory here. Process.WorkingSet is supposed to report the memory usage used by the enitre app (and any component dll's?) but the last time I used it, my memory usage blew out to 110 meg after 6 - 7 hours, and I think this is what caused the high memory usage - this is why I'm after a more "liteweight" of checking memory usage.
Omega501 wrote: Unfortunately, task manager does not report true memory usage, it reports what it "thinks" an app needs :confused: :confused: That's exactly what I have been telling you. Get rid of the WorkingSet, that's not trustable. Omega501 wrote: load up word or something similar open task manager and find the instance of the program you have just started While task manager is open, minimize the app watch the memory usage drop. when you say "memory usage" you are talking about the WorkingSet, right ?
-
Omega501 wrote: Unfortunately, task manager does not report true memory usage, it reports what it "thinks" an app needs :confused: :confused: That's exactly what I have been telling you. Get rid of the WorkingSet, that's not trustable. Omega501 wrote: load up word or something similar open task manager and find the instance of the program you have just started While task manager is open, minimize the app watch the memory usage drop. when you say "memory usage" you are talking about the WorkingSet, right ?
-
First, thanks for the cool tip, will try it out in one of my apps. Is there a sane way of knowing the amount of memory consumed by a .net application, for ex. if I have an application A and application B running, the task manager shows a big chunk of memory used by both these apps. I'm almost sure the task manager is wrong. Is it true that the runtime is being shared by these two apps, how do I find out the individual memory consumptions of these two applications. thanks Kannan
I'm pretty sure the runtime will be shared, but it's a little outside my area. Some of the details depend on what OS you are running (9x vs NT based). For this sort of thing, the www.sysinternals.com website has some pretty cool tools. I also highly reccomend their book, as it might provide answers to those sorts of questions. Burt Harris