tags:

views:

203

answers:

6

I am mostly curious and this isnt a problem. Typically my (C++) apps use very little memory. I thought my current app would take little memory but it uses 3.7mb and VM size of 17.3mb. The app has 4 icons in its resource file, 4 ints in the local(user)settings and is the app LoC is <1k. It detects keyinput and writes a line in a listbox when the user goes idle (calling a windows function). It put itself in the system tray and has a timer set to 100ms.

Theres no arrays or any storage except for a few structs that are less 256bytes together. Why is my app using 17mb+ of VM?

+3  A: 

17 megs sounds about right for a simple C# app.

I guess its the perennial 'hardware use versus programmer productivity' argument.

Chris
+9  A: 

Because it's a managed application, a part of the CLR will also be loaded in memory. Also, the CLR will allocate a bunch of memory so that it may satisfy new object requests (it does not allocate each object from the system). There's also a bunch of other objects that get allocated for each application in a managed model (for instance the thread pool, the garbage collector, etc).

I'm not sure you can do much about reducing that, but on the flip side, you won't see it scale linearly with the app complexity (as in if you make it twice the complexity, it won't use twice the memory).

Danut Enachioiu
+1  A: 

Something to bear in mind is that each managed thread has a 1MB stack, too. If you're doing anything with threads, that's a couple of MB right away.

Mark Simpson
+4  A: 

Grab the .NET memory profiler if you care to see exactly what's taking up that memory.

JP Alioto
+3  A: 

Programs written with the .NET framework inherently have more overhead.

Anonymous Cow
+1  A: 

Don't worry about memory consumption for a Hello World app.

A managed language app handles its memory usage differently than, say, C where every memory allocation has the risk of not being deallocated. In some cases a .NET app may even run faster than an equivalent app written in C++ if the app spends a lot of time in malloc/dealloc because the CLR can put off deallocating/garbage collecting until when the app is idle.

John Simon