Skip to main content
GameDev.net gamedev.net
🔒 Locked

C# memory usage profiling/optimisation

Started by PhilHalf May 9, 2006 at 2:04 PM 3 replies 2k views
Original Post
PhilHalf
PhilHalf
Hi all, I've recently been dabbling in C# and have written a fairly basic application for the company that I work for. The app reads in an XML file that details registry keys and WMI values to display as Labels on a form. It's all working nicely, but I've been asked to see if I can make it use less memory as it will be running all of the time on every PC in the company! Unfortunately I've not really done much optimising and having downloaded a .NET Memory Profiler, don't really understand what it's telling me. Could anyone point me in the right direction or give me any advice on how to profile code (mainly for memory usage, but generally just out of interest) and some general guidelines on keeping resource usage to a minimum? I know it's a bit of a vague question, but I'm not at a stage where I know specifics yet. Thanks in advance for any help or advice, PhilHalf
PhilHalf
PhilHalf
After doing a bit more investigation, I've managed to reduce the memory usage, but I still have a small query.
The application is a simple form displaying data that also has an icon in the notification area (systray). When the application is closed it is hidden and when the icon is double clicked, it is shown again.
I have managed to reduce the memory usage by minimizing the form before it is hidden which sort of makes sense to me. The problem that I have now is that when the application is started (it is hidden at startup), the memory usage is still high. When the form is shown (maximized and shown) and then hidden again (minimized and hidden) the memory usage drops.
I have put some code in so that it calls the show then hide functions which makes the memory usage low to start with, but the form flashes up (as you'd expect) which I don't want.
Is there any way that I could get the form to start minimized and hidden without it using the amount of memory that it does at the moment?

Hope this makes sense.
Thanks for any help or advice,

PhilHalf
edotorpedo
edotorpedo

Well,

Couldn't you use form.visible = false, and hide in the systray. The reason why your application is using more memory than you would expect is because it is loading the .net framework. And by showing your form it's probably using loads of GDI+ (system.drawing) classes.


But I don't see how this would be a problem. What kind of mem-usage are we talking about? On average, services consume from 5-20 MB of ram. Also, is it really necessary to show this data on every PC? Couldn't use just write a windows service that reports to a central server via a webservice? This way, you only have to display data on one PC.

Sounds to me like you're building a sort of Asset Tracking application... need a little bit more info, as it is not clear what you're trying to build here.

Edo
Edo
PhilHalf
PhilHalf
The app is a simple form that displays information such as hostname, ip address, a couple of bits of information from the registry etc. to make it easier for a user to find these things (permissions are restricting access to the command line and other bits).
At the moment, I have a MainApplication class that has a private frmDetails form.
The constructor of MainApplication sets up the notifyIcon then calls
form = new frmDetails;

form is initialized to be minimized and doesn't show up to start with (which is what I need).
I understand that there is some initial loading of the .Net Framework etc. and when the form is visible there's going to be some drawing going on, but once I've opened and closed the form memory usage drops considerably. All I'm trying to do is get it to use less memory initially (after loading everything) without having to show and hide the form once.

Thanks again,

PhilHalf

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.