Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

How to get memory freed as by minimize without displaying the wind

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tomzi - 15 Mar 2006 23:54 GMT
Hello!

Using VS.NET 2003, C++ .NET Form project. I'm beginner to .NET and Win
programming so even if my question is stupid please bear with it.

I'm having problems with starting a program minimized. In theory it's done
easily by setting the WindowState property of the main form to 'Minimized' in
the designer. But that's not all.

Take a very simple VS.NET 2003 C++ project of 1 Form and a few other
controls (say, 1 ContextMenu, 2 MenuItems, 1 NotifyIcon and 1 ICOn resource
file), NO manually added code. When run normally (not minimized), this takes
9-10M RAM (seen in Task Explorer, has ~8M working set in a more thorough
process explorer). A minimize reduces the RAM usage to ~1M. Another restore,
and it uses 2-3M again. Yet another minimize and a footprint of 0.8-0.9M is
reached. No, it doesn't go any further, unfortunately. And there's no
significant difference between a 'release' and a 'debug' build, both start
with huge footprints.

My problem is this: when starting the application minimized, it takes up
9-10M, until I restore/minimize it a few times. So starting it minimized
doesn't reduce the memory usage, but showing the window and minimizing it
afterwards does. Putting the 'WindowState=Minimized' command in the Load or
focus-related events in order to have it immediately minimized doesn't help
(application starts minimized, memory usage remains). Initiating garbage
collection is without effect.

Any ideas, how I could mimic the effects of a 'minimize' without having to
actually display the window? Is there any way to tell the framework
explicitly to drop unneeded memory regions?
Mattias Sjögren - 16 Mar 2006 00:09 GMT
Working set isn't the same as memory usage. I suggest you read the
following.

http://getdotnetco.web101.discountasp.net/GdncStore/free/Articles/The%20Memory%2
0Mystery.htm


Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AMercer - 16 Mar 2006 12:27 GMT
You should follow Mattias Sjögren's suggestion and read up on memory usage in
.net.  The general conclusion you should draw is that .net will take care of
memory business in its own time, and you shouldn't worry about it.

However, regarding your question:

>Any ideas, how I could mimic the effects of a 'minimize' without having to
>actually display the window? Is there any way to tell the framework
>explicitly to drop unneeded memory regions?

The answer is to call kernel32 api SetProcessWorkingSetSize() with -1
parameters and to iterate about three calls to GC.Collect() and
GC.WaitForPendingFinalizers().

I have used these operations to troubleshoot.  A couple of years ago, they
helped me solve a memory leak problem owing to my failure to dispose a
menuitem.  Today there are better tools for chasing memory leaks.  I do not
use these procedures during ordinary operations, and you shouldn't either.  
You should not do these operations to reduce some reported memory numbers
absent a problem.  You should not do these operations to reduce some reported
memory numbers to satisfy others who are complaining about your app's memory
footprint - explain how it works instead.

On the other hand, it is always a good thing to prove that you don't have
memory leaks before deployment.
Tomzi - 16 Mar 2006 15:30 GMT
Thank you for your kind help. I think I understand the situation now. Still,
it's good to know how to force the trimming of the working set, although I
won't be using it.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.