473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why is C# memory hog?

Samishii23
246 100+
So I have a Base C# Windows App... I've changed a few basic options on the Form, BGcolor, Title, Window Type...
No code.
Its 9.5 MB in memory...

Forgive me, but what is that all about?
And is there ways I can not have a C# program so bloated like that?!
Dec 1 '09 #1
3 2220
GaryTexmo
1,501 Expert 1GB
I believe it's just the regular .NET settings, and the garbage collector that runs in the background to clean up all your stuff.

I did a google search for "C# memory footprint" and a discussion on bytes turned up. Hopefully it helps you out :)

http://bytes.com/topic/c-sharp/answe...tprint-startup
Dec 1 '09 #2
Samishii23
246 100+
Expand|Select|Wrap|Line Numbers
  1. public class MemoryManagement {
  2.     [DllImport("kernel32.dll")]
  3.     public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
  4.     public void FlushMemory() {
  5.         GC.Collect();
  6.         GC.WaitForPendingFinalizers();
  7.         if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
  8.         SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
  9. } } }
Error: The type or namespace name 'DllImportAttribute' could not be found (are you missing a using directive or an assembly reference?)

Didn't even make it to the execution portion. Do I need a reference?
Dec 3 '09 #3
GaryTexmo
1,501 Expert 1GB
I believe you need a...

Expand|Select|Wrap|Line Numbers
  1. using System.Runtime.InteropServices;
... at the top. Google for the win :)

Oh hey, just a heads up, calling GC.Collect manually is supposedly not advised unless you really need it. Here's an article to read: http://blogs.msdn.com/ricom/archive/...29/271829.aspx (Again, Google :D)

Is there any particular reason you need to do this? The only real reason I could think of is if you're running on a limited memory platform and are hitting the memory ceiling with your application. Nine times out of ten, you can resolve this by handling your memory management a bit better (allocate data in "pages" instead of one gigantic block, perhaps). The Garbage Collector will free up memory when there is a demand for it, it just doesn't run constantly to save processor power.

I hope this information helps you!
Dec 3 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
4
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage...
4
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
9
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
14
by: Alessandro Monopoli | last post by:
Hi all, I'm searching a PORTABLE way to get the available and total physical memory. Something like "getTotalMemory" and it returns the memory installed on my PC in bytes, and...
1
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
5
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.