|
||
|
|
#1 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
Ok, I know that when you view the memory usage of a .net program, a bulk of the memory shown is the framework. However, I am curious if there is a way to reduce this? Currently, I have a program that finds the handle of window and then depending on if my mouse is near the side of my screen or if the window is active, display the window and if not, hides it. There is no way that this takes between 11 Mb and 13 Mb, but no matter what I try, I cant get this any smaller. So, just wondering if there is anything I should try or do to get this to be smaller (or appear to be smaller).
One thing I am currently doing is hiding my form as soon as the program starts cause it isnt needed. The only thing I need is a notify icon with a context menu to exit. So is there a way to get a program to run without using window forms and still have the notify icon? Anyways, thanks ![]() Edit: Well I found -->this<-- (its a google cache cause the page couldnt be found). This drops me down to around 2 Mb, which is still kind of big for what im doing but its better than before. Still if anyone knows of anything else I could do, it would be appreciated ![]() Last edited by mordero; 12-28-2006 at 03:59 AM. |
|
|
|
|
|
#2 (permalink) | |
|
ConnectUO Creator
Join Date: Jan 2004
Location: In your mom
Age: 27
Posts: 4,763
|
Quote:
__________________
Jeff Boulanger ConnectUO - Core Developer Want to help make ConnectUO better? Click here to submit your ideas/requests Use your talent to compete against other community members in RunUO hosted coding competitions If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team. Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO |
|
|
|
|
|
|
#4 (permalink) |
|
ConnectUO Creator
Join Date: Jan 2004
Location: In your mom
Age: 27
Posts: 4,763
|
Smallest I could get with was this
![]() code was Code:
namespace TestingMemorySize
{
class Program
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private extern static void SetProcessWorkingSetSize(System.IntPtr handle, int min, int max);
static void Main(string[] args)
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
for( int i = 0; i < int.MaxValue; )
i++;
}
}
}
__________________
Jeff Boulanger ConnectUO - Core Developer Want to help make ConnectUO better? Click here to submit your ideas/requests Use your talent to compete against other community members in RunUO hosted coding competitions If you know XNA (even if its just a little) or are a good artist(2d or 3d) and are interested in making games for a hobby send me a pm or drop by #xna in irc.runuo.com. I'm looking to put together a small game development team. Please do not pm me for support. If you are having issues please post in the appropriate forum. Thanks for your continued support of both ConnectUO and RunUO |
|
|
|
|
|
#7 (permalink) |
|
Forum Expert
Join Date: Sep 2002
Location: Houston, Texas
Age: 21
Posts: 3,933
|
this is from a program I used a little while back
Code:
private void menuButtonItem5_Activate( object sender, EventArgs e )
{
long mem = GC.GetTotalMemory( false );
string usage = FormatSize( mem );
this.ActiveWindow.WriteLine( Color.Purple, "*** Current memory usage: {0} ***", usage );
}
public static string FormatSize( long size )
{
if ( size < 0x400 )
{
return string.Format( "{0:#,##0} B", size );
}
if ( size < 0x100000 )
{
return string.Format( "{0:#,###.0} KB", ( (double)size ) / 1024 );
}
return string.Format( "{0:#,###.0} MB", ( (double)size ) / 1048576 );
}
|
|
|
|
|
|
#9 (permalink) |
|
Forum Expert
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
|
it is not good to call GC explicitly in such a case.
let .net do its job on its own.
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." |
|
|
|
|
|
#10 (permalink) |
|
Forum Expert
Join Date: Nov 2003
Location: Illinois, USA
Age: 21
Posts: 2,911
|
Well, seeings as this is just for me, then i see nothing wrong with it. Also, Im only calling it once the program is done doing anything important which is only right after it loads and when it needs to refind the handle of the program.
|
|
|
|
|
|
#11 (permalink) | |
|
Forum Expert
Join Date: Oct 2002
Posts: 1,125
|
Quote:
I agree that in most scenarios you should let .NET handle all of that stuff - that's what it has been designed to do. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|