|
What you see in the task manager is the amount of memory reserved for your program, not how much it is actually using. Every time your program needs memory, the CLR & garbage collector will ask windows for some memory. Then if the program doesn't need the memory anymore, Windows will reclaim it. When you dispose/close your form the garbage collector will have done it's work.
Tip: after you've closed the form, minimize your main form (so your whole program is minimized), and then maximize it again. Now the memory consumption shown in task manager is much lower.
kpr_psna wrote: i hav used gc.suppressfinalize(me) in finalize method.even then there is no reduction in memory usage
Don't do that! SuppresFinalize tells the garbage collector not to finalize your form, so you get the opposite result of what you want.
HTH!
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
[Marc] wrote: SuppresFinalize tells the garbage collector not to finalize your form
True, but he is calling it from within the Finalizer, so it is a bit of a pointless call anyway.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Oh yeah you're right. How can you supress something that is already happening...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick || Fold With Us! || Pensieve || VG.Net ||
|
|
|
|
|
Thanx for ur immediate response
Well,in my application,i have a single billing form which will be operated for the whole day and it has many sub forms.The subforms will finish the process and come back to the main billing form.I am performing a repeated process over there in the main billing form for the whole day.I have maintained all the unused objects to nothing such as
dim iclient as new frmClient
some process()
iclient=nothing
But after closing any sub form,and coming back to main billing form,the memory should get reduced.because in the closed event of subform,i have written MyBase.Dispose().But it doesn't have any effect.In the task manager,the memory usage of that exe gets increased by 2MB,eventhough the sub form gets closed.
Help me out!
Raji
|
|
|
|
|
As the previous poster commented the memory you see in the Task Manager is the memory that your program has "reserved". When you create forms it has to reserve more memory. When the form is closed it is freed up but the memory is still reserved, although not in use. Your application can reuse that memory if it needs it. If the operating system runs low on memory it can have applications free back to the OS the reserved but unused memory so that an application that needs it can have it.
The bottom line is: Don't worry about it - So long as you are calling Dispose on any objects that expose the IDisposable interface when you no longer need the object the memory management in a .NET application will work out fine.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
But my application is getting slower after the memory allocation gets increased.If the garbage collector works properly,then i should not get the out of memory exception.But iam getting that exception if the memory gets increased after a certain time,bcoz billing screen will be in the operation for the whole day.
So how to solve it!
Raji
|
|
|
|
|
Memory isn't the only thing that can cause an OutOfMemoryException. If you don't close and dispose of file handles or all GDI graphics objects used for drawing, or whatever else uses a system handle, you'll exhaust the handle pool and cause the same exception and even slower and slower performance.
Basically, you're looking at a complete review of your code to make sure your Disposing everything you should be when you're done with it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
In most cases it's better to just leave the garbage collector alone. The whole memory management in .NET relies on the garbage collector, and it does quite a good job. Almost always, the garbage collector has much better information on when to do it's job, than what you can anticipate while designing the application.
Don't look at the task manager if you want real memory usage statistics on .NET applications, for that you need something like .NET Profiler. Even if the memory is freed by the garbage collector, it's not released back to windows (unless needed), so you won't be able to monitor actual memory usage in the task manager.
---
b { font-weight: normal; }
|
|
|
|
|
But my application is getting slower after the memory allocation gets increased.If the garbage collector works properly,then i should not get the out of memory exception.But iam getting that exception if the memory gets increased after a certain time,bcoz billing screen will be in the operation for the whole day.
So how to solve it!
Raji
|
|
|
|
|
When the system runs out of memory, it first runs a garbage collection to see if there is anything to collect, before giving up and throwing an exception. So if you run out of memory it's more likely to be due to a memory leak in the application rather than a malfunction in the garbage collection.
Any object that are disposable (inherits the IDisposable interface e.g. having a Dispose method) have to be properly disposed, or they can not be garbage collected.
---
b { font-weight: normal; }
|
|
|
|
|
My name is Landon and I have started to teach myself programming. I am new to vb.Net and I can not figure out how to do a query based on what a user types in a text box. I have tried to figure it out on my own an I can't do it. Here is what I have right now:
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
TextBox2.Text = SqlDataSource1.SelectCommand("select * from EMPMST where EMP_NAME = (@[TextBoxt1.Text.ToString])")
ElseIf RadioButton2.Checked = True Then
TextBox2.Text = SqlDataSource1.SelectCommand("select * from EMPMST where EMP_CORP = (@[TextBoxt1.Text.ToString])")
ElseIf RadioButton3.Checked = True Then
TextBox2.Text = SqlDataSource1.SelectCommand("select * from EMPMST where EMP_SSN = (@[TextBoxt1.Text.ToString])")
End If
End Sub
End Class
If some one could help me or at least explain the concept I am looking for I would be very greatful.
-- modified at 17:41 Monday 9th January, 2006
|
|
|
|
|
What is this TextBox2 suppose to show? I hope it's not data because you haven't executed a query to return any.
But, to fix your SELECT statemnet and actually put the value of TextBox1 into the SELECT statement:
SqlDataSource1.SelectCommand="select * from EMPMST where EMP_SSN='" & TextBox1.Text & "'"
You don't need to put the .ToString() on the end of the TextBox1.Text statement because Text returns a String! Why try to convert a String to a String???
I would highly suggest picking up a book on VB.NET and SQL to get the basics down. There's a lot of misunderstandings coming through in your code. Way too many to discuss in the any forum.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Yeah, I know. His code is messed up in so many different directions, I didn't want his head to explode when he read your article.
But I do have your article bookmarked so I can refer people to it quickly!
Great job!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I see what you are saying. I am new to this thing and I have tried looking at a book ,but I have not found the question that I was looking for. I know I still need the book for all of the basic stuff I have not learned yet and this ia a problem that happens when you teach yorself. I think that I can make this code work though, The sqldatasource1 is a feature in Microsoft web development that has the connection and basic sql query. This could be like you said a dead end and I may have to start over and I will if that is what it comes to. Basically the best way I learn is to just sit down and try to make something. I have built several little programs and website in just a few weeks where if I was in a class or following the book I would not have been able to do this. I appreciate all of the advice that I have received though.
-- modified at 10:03 Tuesday 10th January, 2006
|
|
|
|
|
I do see what your saying because I'm completely self taught. There isn't a single computer class that I haven't walked into and been able to teach it on-the-fly.
But, there is so much wrong with your code on so many levels, I can't even begin to describe how to get it to work, other than scrapping it and starting over. Understand each line of code before you move on to the next. You have to understand what the classes your using require and how to build up those pre-req's first, like the SqlDataSource.
Landon Spann wrote: Basically the best way I learn is to just sit down and try to make something
Yes it is. The problem is your actually making it harder on yourself by not getting the basics first. You're trying to climb Mount Everest without having climbed a simple hill first. Learn to hike before your learn to climb. It'll make throwing these applications together much easier and quicker in the long run. Take it from someone who's been there and done it the hard way. Now that I have all the basics down and the concepts, I can pick up any language and write code using it, without having seen it before.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I appreciate the advice and before starting another project I will try to master the basics.
|
|
|
|
|
In addition to Dave's comments, you should NEVER use the text from a textbox in a select like this without first cleaning it to protect from injection attacks.
Like Dave said, you're really lost at sea here, you need to abandon this project for now, buy a beginners book and work through it. One other point - you should never keep the default variable names. What makes textbox1 different from textbox2 ? How about txtInput and txtOutput. See how that would make your code more readable ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi, my problem is that I have a tab control, consisting of 4 tab pages and 4 user controls, 1 user control on each tab page. I would like to call the event method tabcontrol.selectedindex changed to load the data into the user control when the user clicks on the form, and not immediately when the selected index is changed. I need this because when certain users open the application the application will hide/remove a tab page if the user does not have access to that particular page. Upon removal, visual studio.net sets the selected index to the page index immediately before the one being removed. My loading of data was originally located within the load method of the user control itself, but this is causing my application to lag at startup when I need to remove a tabpage because it is loading that page when I remove the tabpage.
My code currently looks like eg.:
Public Sub tcCompany_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tc_Company.SelectedIndexChanged
Select Case UCase(Me.tc_Company.SelectedTab.Name)
Case "TP_COMPANYNOTES" 'checks to see if user clicked the notes page
If Me.tcmediator.p_ucNotes.comb_companyName.Items.Count <= 0 Then 'checks if combo has data
Call Me.tcmediator.p_ucNotes.userClickedForm() 'loads data
End If
Case "TP_COMPANYCREDIT" 'checks to see if user clicked the credit page
If Me.tcmediator.p_ucCredit.comb_companyName.Items.Count <= 0 Then 'checks if combo has data
Call Me.tcmediator.p_ucCredit.userClickedForm() 'loads data
End If
end select
end sub
Thanks for the help
eatwork
|
|
|
|
|
Why not load your control when it becomes visible for the first time ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi Christian, thank you for your input, I can't load the control during the load method of the control because the control on the 4th tab page loads immediately after deleting the 5th tab page, because the tab control automatically sets the selected index to the index of the control...not sure how to explain this, but if you delete tab page 5, then the tab control within visual studio will set the selected index to tab 4 upon loading the tab control. when that happens tab 4's load method will execute causing the loading of the form to be an extra 3 seconds slower than it needs to be. Not too sure if that answers your question/answer. or if I am way off base could you explain your solution a little more please? thank you.
eatwork
|
|
|
|
|
No, I meant during the visible changed event. When it becomes visible.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you Christian for your reply, sorry it took me so long to reply. I will give your suggestion a try.
eatwork
|
|
|
|
|
does any1 know how to shutdown, restart, standby, hibernate, or logoff the Windows XP system?
i know its to do with:
shutdown(*)
* = number corresponding to shutdown type...
i dont know how to perform these tasks... can any1 help me?
thanks...
Adam Forbes
|
|
|
|
|
I would think that you can not do this from an application.It seems to me that it would be too much of a security risk, but if you find out how let me know.
"People who never make mistakes, never do anything."
My Blog
|
|
|
|