abnormal memory occupation?

Z

Ziphyre

Hi,

I have a simple windows application, it doen't have any form, or
expensive resource, just a simple exe. Its size compiled in release mode
is approximately 23KB. But when I run it, its size on memory is approx
12MB (megabyte!!!). Here is a simplified version of the code, I'll be
more than happy if you could tell me is this normal, or what can cause
the problem

Thanks


using System.Text;
using System.IO;
using System.Collections.Specialized;
using System.Web;
using System.Threading;

public class AutoBuy
{
public static void Main()
{
while ( true )
{
CommTest.GetData();
Thread.Sleep(3000000);
}
}
}


public class CommTest
{
public static void GetData()
{
//... declaration of 3 string
HttpWebRequest hreq = CreateKocGETRequest();
//mark1
HttpWebResponse hresp = (HttpWebResponse) req.GetResponse();
StreamReader respReader = new
StreamReader(hresp.GetResponseStream());
rstring = respReader.ReadToEnd();
respReader.Close();
hresp.Close();
//mark2

hreq = CreateKocPOSTRequest("login.php", ckyString,
byteArray);

//again mark1 to mark2 with different data, nothing
//special

}

public static CookieCollection GetCookies(WebHeaderCollection
hdCol)
{
//a function which extracts 3 cookies from header files
//works only with int and string's

return ckyCol;
}

public static string GetHash(string s)
{
//another function just with ints and strings

return astring;
}

public static HttpWebRequest CreateKocGETRequest()
{
HttpWebRequest KocReq = (HttpWebRequest)
WebRequest.Create("http://www.temp.com");
//sets 5 five properties

return KocReq;
}


public static HttpWebRequest CreateKocPOSTRequest(string path,
string ckyString, byte[] postData)
{
HttpWebRequest KocReq = (HttpWebRequest)
WebRequest.Create("http://www.temp.com/" +
path);

//sets 7 properties with strings
return KocReq;
}
}
 
A

Anders Borum

Hello Ziphyre

This is caused by the CLR thats responsible for loading the required
application. Currently there's a footprint of about 12 MB, but if I
understand Jason Zander from the CLR team correctly, this is something
they're working on (as well as startup times).

Not sure it'll be better with .NET 2.0, but I'm sure they're doing their
very best (in all aspects of the .NET framework actually).
 
I

Ian Griffiths [C# MVP]

Strictly speaking, the minimum working set footprint of the CLR is more like
5.5MB, in my experience.

However, that goes up as soon as you start using certain bits of the .NET
Framework. There are lots of pieces of it that have a substantial hit as
soon as you use them. Windows Forms, for example.

So 12MB is not unusual for a Windows forms application that does nothing.
 
J

Jon Skeet [C# MVP]

Ziphyre said:
I have a simple windows application, it doen't have any form, or
expensive resource, just a simple exe. Its size compiled in release mode
is approximately 23KB. But when I run it, its size on memory is approx
12MB (megabyte!!!). Here is a simplified version of the code, I'll be
more than happy if you could tell me is this normal, or what can cause
the problem

That sounds a little high, but not huge. There's a significant initial
memory use in .NET (even a program which *just* sleeps for 10 seconds
takes about 3.5MB on my box) but you should find that as your program
gets larger, your memory requirements don't go up by much more than you
expect - in other words, there's a large initial usage, but it's not
particularly inefficient in terms of actual data.
 
Z

Ziphyre

Thanks for the answers, i was pretty sure that somethings were wrong but
it's quite reasonable when you put it that way

thanks again
 
W

Willy Denoyette [MVP]

And to add what others said, don't ever compare file size of your assembly
with memory consumption, both are not related.

Willy.
 
W

Willy Denoyette [MVP]

The footprint in v2.0 is a bit higher, because the modules loaded are
getting larger in v2.
The good news is that much of the Framework is now mapped to shared pages,
which considerably reduces total memory consumption when multiple .NET
applications are loaded.

Willy.
 

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

Top