|
Actually I have seen this with non-.NET programs as well. When an app gets minimized Windows can swap out memory that is not needed and free things up. I just did this with Word and it went down to 1-2M when minimized and then back up to about 5M when it is brought back up front. Another app that we run here at work went from 18M while it was running, down to 1-2M when minimized and then back up to 6M when it was opened again. This definately is not anything to do with .NET itself.
Steve Maier, MCSD MCAD MCTS
|
|
|
|
|
On minimize, two things happen. THe first is that the framework releases most of the extra memory it's allocated from the OS to cover against future requests. Since form initialization uses alot more memory than is needed during runtime, apps that don't substantially increase the ammount of data in ram after loading the form tend to have a large amount of extra availabl. The amount held is determined by the framework, and is partially dependent on how much the system has available. The reason for de/allocating in large chunks rather than small ones is that getting memory from the OS is a costly operation. A system wide memory shortage will cause the OS to send 'return extra memory' messages and do the same thing. The second is that most of the app is moved from system to virtual memory. On restore, the code is only moved out of VM on an as needed basis.
|
|
|
|
|
PS Your apps memory usage isn't much higher than mine which runs happily on an NT4/p3-500/256mb testbox, unless your client machines are substantially older or already heavily burdened with other apps you shouldn't have a problem.
|
|
|
|
|
The 'Mem Usage' column in Task Manager is actually the current working set size. The working set is the set of physical memory pages which the OS thinks are currently necessary to run the program. Periodically, about once a second, a thread in the OS called the balance set manager wakes up and trims (removes) pages from each working set on the system, to ensure that there are always enough free physical pages of memory to satisfy demand. There is also an upper limit of working set size for each process, which is defaulted to about 1.5MB, but this is really an advisory limit - if there are enough free pages, this number is ignored. You can set your process's limits with the SetProcessWorkingSetSize function, but there's no benefit in doing so.
When the USER subsystem minimizes a window, it automatically asks the operating system to trim the process's working set, since the assumption is that you aren't going to be using it again straight away. You can get the same effect by calling SetProcessWorkingSetSize , passing -1 for both minimum and maximum working set size parameters.
Pages are added to the working set by allocating them, or, after they've been trimmed, by accessing them. If your program has good locality of reference, the working set will normally stay quite low.
To see how much load you're putting on both physical memory and the page file, enable the VM Size column. This is equivalent to the Process: Private Bytes counter in the Performance tool (in Administrative Tools).
The .NET Framework manages all your allocations from a set of virtual memory allocations. The garbage collector generally just moves data around within the existing allocations, until its newest generation becomes full, at which point it will ask the OS for a new block (referred to as a segment). If it does have a completely free segment after performing a collection, it may return it to the OS - this is the only way that the VM Size column will go down.
To keep the size of the GC heap down, ensure that you're getting rid of your objects promptly. If an object implements the IDisposable interface, or otherwise offers a Close or Dispose method, you must call it when you're finished with the object. If you don't, when the GC runs (and the object has a finalizer) it will go onto a queue (called freachable) for the finalizer thread to run the finalizer. The memory will only be released back to the GC heap when the GC runs again to collect the older generation that the object is now in, after its finalizer has run.
Other things to do are to simply allocate fewer objects. .NET applications can often be 'object-happy' - it's so easy to create an object that it is often done without thinking. To see how many objects you're allocating, and where you're allocating them, run CLR Profiler[^] (for 1.1[^]).
For more on how the GC works, see Maoni Stephens' weblog[^] and this presentation[^] (PPT, 401kB) from PDC 2005.
-- modified at 16:25 Wednesday 23rd August, 2006
|
|
|
|
|
The responses by Dan and Mike are absolutely correct. You also should not rely on GC.Collect, as it interferes with the natural GC collection schedule, which can actually hurt your application performance. The GC runs on its own thread and actually freezes your applications main thread while it is running. Instead of calling GC.Collect when the child form is closed, you really should be calling the Dispose method of the form.
In addition to the blog mentioned, you can check http://www.codeproject.com/useritems/idisposable.asp[^] for an explanation on how to implement the Dispose pattern.
|
|
|
|
|
I know that value type variables are stored in stack and ref variables are stored in managed heap. I wanted to know why.
Thanks in advance
|
|
|
|
|
In most cases (not within classes), ref variables are on the stack as well. They refer to objects allocated on the managed heap.
Best,
Jun
|
|
|
|
|
karan vidyut wrote: I know that value type variables are stored in stack and ref variables are stored in managed heap. I wanted to know why.
I think you mean "value objects" and "reference objects".
|
|
|
|
|
Reference types (e.g. objects) are always stored in the heap.
Value types declared inside a class is stored inside the object data on the heap.
Value types declared as local variables in a method are stored on the stack.
If reference types would be stored on the stack, they would live exactly as long as the method call where they are created. They could not be freed earlier and not survive after. Also the stack has a limited size (2 MiB by default, IIRC) and can not be expanded at runtime.
If local variables would be stored on the heap, it would mean that most method calls would allocate memory on the heap, vastly increasing the heap turnover and adding a lot of overhead.
---
b { font-weight: normal; }
|
|
|
|
|
How to emulate the File->Send->Page by email functionality given by IE.
Is it possible to achieve the same result on click of a button using asp.net
|
|
|
|
|
hi
i have developed a test page in asp.net 2.0 (VS 2005), and tried to hold it on my domain. it is a simple page with three textbox and a button, web.config is also default, but it gives error
Server Error in '/' Application.
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Unrecognized configuration section 'connectionStrings'
Source Error:
Line 10: <configuration>
Line 11: <appsettings>
Line 12: <connectionstrings>
Line 13: <system.web>
Line 14:
|
|
|
|
|
Since this element is new in .NET 2.0, that would suggest that your host server hasn't been upgraded to support .NET 2.0 and the server is trying to run your page with the .NET 1.1 runtime.
You need to get the server upgraded with .NET 2.0.
|
|
|
|
|
Hi All,
I want to write some program that control windows behavior, like hiding the desktop, disabling Ctrl+Alt+Delete, Hide Start Menu, and all this stuff, how can i make under .NET
and plz give me a detailed answer coz am new to this field
thanks in advance
|
|
|
|
|
Go ahead and try yourself first. If you encounter specific questions, post them here and some of us may be able to help.
Best,
Jun
|
|
|
|
|
I'm already done with most of this project -this part is only a small part of the project- anyway, am doing my best to have answers for my questions
|
|
|
|
|
HI
i have discovered all messages from a dbx file
now how will i put back ina dbx file
|
|
|
|
|
to all d wizards out there:
I have a problem here with regards to Axis Web Service. I have an ASP.Net Web Application and I have to pass values on An Axis Web Service that has been created... Can somebody tell me what to do with regards to this...
Thanks a lot..
|
|
|
|
|
By passing data do you mean invoking a method? There should be no problem for an ASP.net web application to consume a web service that is being hosted on tomcat(or any java server) through axis. All you need to do is add the URL of the web services WSDL to the web application to the 'web references' part of your solution tree.
-Steve
|
|
|
|
|
Hi,
I have to write an application that will start applications that are scheduled at some time. Lets us assume that I have 5 Aplications (exe files) that have to run at 11:00AM.
I can start these applications by using Process class, but my requirement is that all the n Applications should be started at the same time rather than in a sequence.
Any suggestion / ideas will be appreciated.
Thanks in Advance,
Thanks & Regards,
Mohammed Imdadullah
|
|
|
|
|
Md.Imdad wrote: but my requirement is that all the n Applications should be started at the same time rather than in a sequence.
You won't be able to do that unless your system has many CPUs. Otherwise, the executions will be sequent, even with multiple threads.
Best,
Jun
|
|
|
|
|
Ok first, I'll outline my project. It is a web application made to search and display records of archived technical documents. What I have right now is a page that uses datagrids (via drag and drop from Visual Studio 2005) to display columns of data from my SQL Test server.
What I need now is a way to create a simple form text box and create and pass a variable to the SELECT statement within the datagrids. All my attempts at this thus far, using both ASP and C# and MSDN knowledgebase, have ended in frustration.
Here is the code of the datagrid:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="OVERVIEW" HeaderText=" " SortExpression="OVERVIEW" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="
<%ConnectionStrings:trdConnectionString2 %>"
ProviderName="<%$ ConnectionStrings:trdConnectionString2.ProviderName %>"
SelectCommand="SELECT [OVERVIEW] FROM [SUDS_TRD] WHERE [IDENT]='1'">
</asp:SqlDataSource>
What I need to do is where it says [IDENT]='1', is have that "1" be a parameter passed from an HTML form, perhaps looking like this WHERE [IDENT]='"% strIDENT %"', yet I do not know how to pass a parameter from an HTML form into that SELECT statement. Any help would be great as this is a problem holding up my project.
To reiterate, I need to:
A. create an html form text box
B. pass that textbox as a variable
C. place that variable into the SELECT statement for the ASP datagrid.
Any help would be great, example code, whatever it takes; the simpler the better =) Please just don't send me to MSDN's Datagrid Knowledge Base page as 1/2 the stuff there doesn't even work =[.
Thanks for any help in advance!
|
|
|
|
|
I have written a C# application that uses very large objects: 1mb to 3mb,
it has what seems to be a memory leak. According to microsoft and all
my colleague .NET Applications DON'T leak. So I looked for an answer and came
across that:
"The large object heap is never compacted..."
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/DBGch02.asp[^]
a quote from microsoft article about memory debugging.
Isn't that means that when a memory is freed a hole is created and not handled?
Is that the reason my app is leaking?
Thanks
b.v.
|
|
|
|
|
BarV wrote: According to microsoft and all
my colleague .NET Applications DON'T leak.
True, to a point. A .NET app can only leak unmanaged resources or memory allocated through unmanaged means.
BarV wrote: Is that the reason my app is leaking?
What makes you think your app is leaking? Don't tell me you relied soley on the numbers you saw in TaskManager?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
No. I relied on the Private Bytes counter in the prefmon.
b.v.
|
|
|
|
|
BarV wrote: Isn't that means that when a memory is freed a hole is created and not handled?
No, it doesn't.
The hole is created, all right, as the heap is not compacted, but it's handled. The memory will be used for allocating new large objects.
---
b { font-weight: normal; }
|
|
|
|