Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Why is my C# so big?

Why is my C# so big?

Scheduled Pinned Locked Moved C#
csharpannouncementdebuggingxmlhelp
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adrian Hall
    wrote on last edited by
    #1

    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

    D O B 3 Replies Last reply
    0
    • A Adrian Hall

      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

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A Adrian Hall

        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

        O Offline
        O Offline
        Omega501
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • O Omega501

          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

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          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.

          O 1 Reply Last reply
          0
          • A Adrian Hall

            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

            B Offline
            B Offline
            Burt Harris
            wrote on last edited by
            #5

            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

            K 1 Reply Last reply
            0
            • B 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

              K Offline
              K Offline
              Kannan Kalyanaraman
              wrote on last edited by
              #6

              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

              B 1 Reply Last reply
              0
              • S Stephane Rodriguez

                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.

                O Offline
                O Offline
                Omega501
                wrote on last edited by
                #7

                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.

                S 1 Reply Last reply
                0
                • O Omega501

                  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.

                  S Offline
                  S Offline
                  Stephane Rodriguez
                  wrote on last edited by
                  #8

                  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 ?

                  O 1 Reply Last reply
                  0
                  • S Stephane Rodriguez

                    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 ?

                    O Offline
                    O Offline
                    Omega501
                    wrote on last edited by
                    #9

                    .S.Rod. wrote: when you say "memory usage" you are talking about the WorkingSet, right ? Nope, as far as I know, WorkingSet reports the correct memory usage of the app. Task manager lies a lot, so it's not something you can trust.

                    1 Reply Last reply
                    0
                    • K Kannan Kalyanaraman

                      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

                      B Offline
                      B Offline
                      Burt Harris
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups