|
harold aptroot wrote: then let me ask it like this, how should I do "the same"?
You don't. You're worried about something that happens completely automatically. The .NET CLR does a very good job of managing memory. If your code frees a bunch of objects, the memory isn't freed immediately. The Garbage Collector gets around to freeing them eventually, whenever it needs to. When an object is finally freed, the memory is returned to the Managed Memory Pool. The reason it doesn't get returned to Windows immediately is because future allocations are faster out of the Managed Pool if there is sufficient memory in the pool. If not, the memory manager has to go to Windows to allocate another block of memory, add it to the pool, then allocate the new object. Now, if Windows needs the memory back, the .NET CLR is more than happy to remove any free memory from the Managed Pool and return it to Windows - entirely automatically. You don't have to do anything.
|
|
|
|
|
I know we shouldn't, but mostly I'm just curious
Ok so basically what you say here, when you minimize a program, windows will dump part of it in the swap file. Correct?
What happens if you don't have a swap file, like me? Nothing?
|
|
|
|
|
harold aptroot wrote: What happens if you don't have a swap file, like me?
Why would you not run with a swap file?? You're only hurting performance doing that.
harold aptroot wrote: when you minimize a program, windows will dump part of it in the swap file. Correct?
Like Senthil said, Windows will try to free up an much physical RAM as possible by swapping out pages not being used, not not free either, to disk. If there is no swap file, the stuff stays in memory, reducing the amount of RAM Windows can use for caching and buffers.
|
|
|
|
|
Dave Kreskowiak wrote: Why would you not run with a swap file?? You're only hurting performance doing that.
I have 4GB ram, swap space is not needed, the reduced amount for caching and buffers is usually between 3 and 3.5 GB - so there is really no need for a file of at least 4GB (but defaulting to 6GB) that will cause extra disk-rattling
Going lower than 4GB gives sporadic warnings - I wouldn't mind having a 128MB pagefile or so, but windows complains
edit: actually it seems to be slower with a swap file
And this is using XP of course, I wouldn't touch Vista with a 100yard pole - I heard Vista has more trouble without a swap file
|
|
|
|
|
harold aptroot wrote: But I still want to know, you know, the minimize trick makes me curious as to how it manages to do whatever it is it's doing - and what is is doing? Forcing a GC? Releasing unused pages? Something else?
Windows does this, not .NET. When you minimize a GUI application, Windows trims the working set of the process (SetProcessWorkingSetSize[^], which writes out unused memory pages to disk, reducing the physical memory consumption of the application. What Task Manager shows in the "Mem Usage" column is the working set size, so that goes down. Windows does this so that the applications which appear in the foreground get some more physical memory to play with.
But in reality, there is no decrease in virtual memory consumption.
|
|
|
|
|
Thanks, precisely what I wanted to know
|
|
|
|
|
Ok I have done as you suggested. I have also converted the Threads I was using into background workers due to them only needing to work when that form was loaded and no where else. I think this increased the memory usuage during that form being loaded, but disposed of everything when I closed it.
I noticed that I could get it to jump to 130MB, close the edit form and it would still be there. BUT, when I minimized the entire application the memory jumped down to like 5-10MB from 130MB. Is that good or bad? It doesn't seem to go down right then unless I minimize it.
|
|
|
|
|
It all sounds normal.
Minimizing the main form causes Windows to reclaim part of the Working Set.
Just closing some forms won't achieve anything right away: the GC only runs when it has to, as in your code trying to create a new object and not enough memory being available. Closing a window is unlikely to cause that, unless you create objects in the FormClosing/FormClosed handlers.
|
|
|
|
|
Are You using Thread Under thread ?
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
When the form loads it loads information from SQL. One information that takes a while remotely is a picture. Since the pictures put in there are usually 1-3MB in size. So I use thread to call a method to do this.
Thread newThread = new Thread(new ThreadStart(GetPicture));
newThread.Start();
This is how I call it. The TAG (Identity) is passed to the form when it is loaded from another form. So how I get the picture I want is by using that Tag.
private string TAG;
public EditInventory(string TAG)
{
this.TAG = TAG;
InitializeComponent();
}
|
|
|
|
|
According to ur logic Thread Start Loading picture but at this time Second Thread Starts.So at same time Multiple Threads are Running. So it's take Max CPU Usage and CPU Memory.
You Should remove the concept of thread for GettingPicture. Or when first thread finish then second thread should run.
Best Regard
Anubhava Dimri
mailto: anubhava.prodata@gmail.com
|
|
|
|
|
Hi,
I have just come across a problem where i have a block of code which exercutes when the selectedindexchange event kicks in. However, because i load my form becuase i have a datagrid and the combo box is binded the selectedindexchnage event is exercutes again making duplicate data . How do i approach avoiding this?
I have looked at diffrent events but cant see one that wil solves my problem,
any suggestions or simillar examples anyone can point me to?
Many Thanks
D.Arnold
dave1816
|
|
|
|
|
If I have a situation where firing an event causes the event to fire again, or similar, I tend to use a flag to tell me when I want the event firing code to run, and when I need to ignore it.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
Graus is true, but i suggest you to use following when binding comboBox to a data source.
you have selected index change event for combo box, you can simply de attach that event before binding comboBox or what ever causes comboBox change index event to fire.
i have a combobox named "cmb1" with selectedIndexChangeded named "cmb1ChangedIndex".
simply follow this
cmb1.selectedIndexChanged -=selectedIndexChangeded;
//do binding here for both comboBox or what ever cause comboBox selectedChanged event //to fire then
cmb1.selectedIndexChanged +=selectedIndexChangeded ;
|
|
|
|
|
Right never used a flag but will research into it and also go with the bidning solution.
Many thanks for you replys
I will try the code the solution tonight ( fingers cross it works)
I will post a heads up and let you know
Thanks again
D.Arnold
dave1816
|
|
|
|
|
|
I have many applications which were working fine but ever since the DBA's re-installed SQL now some of the applications do not work. I tried everything and I could not find a solution. During SqlConnection's Open() method I get the following exception:
"Instance Failure"
Since the message is so descriptive (right!), it is hard to tell what the problem is.
I tried to connect to it by adding a new datasource to a dummy project using VS2005 and give me the same message in a message box. Now I know it is not my app but something else.
Any idea what could be causing this? It only happens with servers that have instance names and not the default.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Hi,
This[^] might help.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks but as I said I tried everything (almost) but it did not solve my problem. I was hoping someone here have experienced the same and can help me.
I have visited all those links where your trick takes me.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
What's the quickest way to test/check the current node when doing a loop whether that node has it's own subtree of nodes? Or rather that it just has a value.
like:
while (xr.Read())
{
//xr.checkforsubtree
If I do a:
xr.ReadElementString(); - then it advances the current node as well
I want some kind of if statement to check it before hand.
if xr.hasvalue does not work
}
|
|
|
|
|
The problem with the XmlReader class is that it can't predict the future. You can't find out if there are child nodes to the current node you just read without reading through the child nodes. If you really need this, try looking at XmlDocument instead where you read the entire XML file, then you can sift through all the nodes to get the information you want.
|
|
|
|
|
Hi.
I'm gonna create a textbox as when a user press Enter key, <br /> insert into the textbox instead of \n or \r\n
Could you guide me ?
Thanks
|
|
|
|
|
Hi,
Controls that accept keyboard input have KeyDown, KeyUp, KeyPress events. Use one or more of them to achieve your goals.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks . I know them.
I don't know how I can implement it
|
|
|
|
|
They did invent a beautiful thing especially for you, it is called documentation.
If you don't know where it is, Google may show the way. Studying a book on the subject might be useful too.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|