25 MB

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

I finished a fairly trivial C# windows application. Task Manager reports
that this application is 25 MB! Yes it is the release configuration.

Any suggestions on how to investigate how this dinky application blew up
into these humongous proportions?
 
Hello

Trivial doesn't always mean light-weight, on the contrary sometime you have
to make your code more sophisticated in order to reduce the memory usage of
the application. And sometimes one line of code like the following can make
your application use a lot of memory
byte[] array = new byte[100000000];

I suggest you use a memory profiler to see where the memory goes

Best regards,
Sherif
 
Even for a trivial Windows application the CLR and a lot of related native
code libraries must be loaded, a bunch of assemblies loaded, a number of
application domains initialized, the GC heap reserved, System.WinForms
classes loaded and Jitted. That all means that the initial memory footprint
is high and certainly higher than non managed applications. Once the
appdomains are created, winforms is initialized etc... a lot of memory pages
are no longer (directly) needed.
However, these pages, are only returned to the OS when there is memory
pressure, when this happens the OS will trim the Working sets of the loaded
processes (managed or unmanaged), on XP and higher the OS will also requests
the managed applications to return unused pages to the OS.

Willy.
 
Interesting ... and since I have 1GB of memory there is no contention and
the trimming never occurred.

Is there a way to induce the working set trimming after initialization in an
environment where there is no external page contention?
 
Thom said:
Interesting ... and since I have 1GB of memory there is no contention and
the trimming never occurred.

Is there a way to induce the working set trimming after initialization in an
environment where there is no external page contention?

Minimizing the application will generally trim the working set.

See the docs for the Win32 SetProcessWorkingSetsize() API for how to do
this from your program. I don't think there's a framework method to do
this, you'll probably have to P/Invoke the Win32 API.

If you end up actually doing this, test well to make sure it doesn't
cause any unintended slowdowns.
 
mikeb said:
Minimizing the application will generally trim the working set.

See the docs for the Win32 SetProcessWorkingSetsize() API for how to do
this from your program. I don't think there's a framework method to do
this, you'll probably have to P/Invoke the Win32 API.

If you end up actually doing this, test well to make sure it doesn't
cause any unintended slowdowns.

My recommendation is to not fiddle w/ it unless there is a specific need. To
wit, all that I've seen is that the OP looked in the task manager and saw
25MB. That is not justification to mess w/ working set, profiling, etc.

What needs to be asked first is 'what problem needs to be resolved', and then
systematically resolve it.
 
Well, I don't see anything to worry about, it's another reason why this
whole managed codebase is getting rather annoying, less to say the GC. But,
if you are really concerned and you know that your proggie isn't using that
much RAM, call a GC.Collect() after everything initiallizes. Not something
I recommend, but it is an option to force the "JITter" to release the unused
memory before you run out. With 1GB of RAM, I wouldn't give it a second
thought though, but you did want a solution.

HTH,
Sueffel
 
I wouldn't worry about it. You're probably never going to use a program
that trivial. I would worry if it was a big program that seemed to be
wasting memory, then there's profiling and optimizations you could do. You
could probably add a lot to the program and make it not so trivial and it
will probably still take up the same amount of memory. A lot of that stuff
is the initial CLR and winforms objects.

..02
jim
 
Yes you can, using PInvoke as mikeb said and the FCL contains a class that
allows you to reduce the max. WS, but you shouldn't do it as there's no need
for it. Just let the OS do it's job, it knowns a lot more about what pages
are idle, and their age, not only your pages but all processe's pages in the
system. If you plan to trim your workingset be prepared to take a number of
hard pagefaults when your program jumps to a page you moved to the pagefile.

Willy.
 
Hello
I suggest using this one
http://www.scitech.se/memprofiler/

Best regards
Sherif

Thom Little said:
What memory profiler do you recommend?

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Sherif ElMetainy said:
Hello

Trivial doesn't always mean light-weight, on the contrary sometime you have
to make your code more sophisticated in order to reduce the memory usage of
the application. And sometimes one line of code like the following can make
your application use a lot of memory
byte[] array = new byte[100000000];

I suggest you use a memory profiler to see where the memory goes

Best regards,
Sherif
 
Thanks to everyone for bringing me up to speed.

The reason I go started down this road is because I showed this dinky little
application to a customer and in Task Manager it was reported as 25 MB and
that was simply astonishing.

The cause is that it was one machines with 1 GB of memory and there was no
manor contention.

Now that I know (enough to be dangerous) I can explain what is happening.

I have no intention of dialing with it.
 
Thank you ... I will check it out.

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Sherif ElMetainy said:
Hello
I suggest using this one
http://www.scitech.se/memprofiler/

Best regards
Sherif

Thom Little said:
What memory profiler do you recommend?

--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
--

Sherif ElMetainy said:
Hello

Trivial doesn't always mean light-weight, on the contrary sometime you have
to make your code more sophisticated in order to reduce the memory
usage
of
the application. And sometimes one line of code like the following can make
your application use a lot of memory
byte[] array = new byte[100000000];

I suggest you use a memory profiler to see where the memory goes

Best regards,
Sherif
 
Hi Thom,

I am glad the community's reply makes sense to you.

If you have any further concern, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top