form opening problem

alvinblim

Well-known member
Joined
Jan 7, 2006
Messages
46
Location
malaysia
Programming Experience
3-5
i found that, my computer usage memory alway increase when i open new form.
Program: visual studio 2003(vb.net)


opening form coding :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form2 As New Form2
form2.Show()

End Sub

Closing form coding:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub

i hope that someone can guide me to solve this problem.
thank you
 
Opening any program causes memory usage to increase. If youre complaining that it doesnt go down when you close the form, then Dispose() it and wait an arbitrary amount of time (hours, if this app is not used often) for the garbage collector to free the memory.
 
cjard,
my program alway increase the memory usage. it increase until 120,000kb or 160,000. but after close the form the memory usage still cant free my memory. is it this is a limitation of visual studio 2003 or .ne framework 1.1? do u hv any idea to free up the memory immediately?
 
There is code on the web somewhere, I think it is from Microsoft - you can call the Garbage Collector and it will free the memory there and then.

The memory will not decrease until you properly exit your application, most people use Application.Exit()
So if your 1 form is your actual app, using form me.close will still leave your app in memory - you need to replace me.close with application.exit
 
cjard,
my program alway increase the memory usage. it increase until 120,000kb or 160,000. but after close the form the memory usage still cant free my memory. is it this is a limitation of visual studio 2003 or .ne framework 1.1? do u hv any idea to free up the memory immediately?

.NET is slightly heavier on memory than other languages but it doesnt mean much.. Youre probably worrying about it more because you can see it.. However, if youre doing something silly like downloading an entire database into a dataset on the form, then you will experience that. We dont know enough right now to actually help. Post some more info on what your form does.

Arg81, i dont really recommend invoking the Garbage Collector yourself; the framework will work out when to do it and do it as necessary
 
this is my declaration at the begining of the form
VB.NET:
Imports System.Data.SqlClient
Public Class AddNewBook
Inherits System.Windows.Forms.Form
Dim connection As New SqlConnection
Dim command As SqlCommand
Dim SQL As String
Dim SqlDtAd As SqlDataAdapter
Dim DS As DataSet
Dim DR As DataRow
Dim A As String
Dim myConnection As System.Data.SqlClient.SqlConnection
Dim myCommand As SqlCommand
Dim ra As Integer
Dim strBuffer As String
this is my adding new record into database. This page is to adding a new data into database.
VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If txtSerialNo.Text = "" Or txtTitle.Text = "" Or txtAuthor.Text = "" Or txtPublisher.Text = "" Or cbAcqDate.Text = "" Or txtAcqCost.Text = "" Then
MsgBox(" Please fill in all the following important detail before continue to the next process.", MsgBoxStyle.OKOnly, "Detail Not Complete")
Else
Dim SQL
Try
myConnection = New SqlConnection
myConnection.ConnectionString = strBuffer
'you need to provide password for sql server
myConnection.Open()
SQL = "Insert MasterList (AssetNo,PAno,ControlNo,SerialNo,Description,Autho 
r,Publisher,AcqDate,AcqCost,Volume,ItemCategory,Mo de) 
Values (@AssetNo,@PAno,@ControlNo,@SerialNo,@Description, @Author,@Publisher,@AcqDate,@AcqCost,@Volume,@Item Category,@Mode)"
myCommand = New SqlCommand(SQL, myConnection)
myCommand.Parameters.Add("@AssetNo", "-")
myCommand.Parameters.Add("@PAno", "-")
myCommand.Parameters.Add("@ControlNo", "-")
myCommand.Parameters.Add("@SerialNo", txtSerialNo.Text)
myCommand.Parameters.Add("@Description", txtTitle.Text)
myCommand.Parameters.Add("@Author", txtAuthor.Text)
myCommand.Parameters.Add("@Publisher", txtPublisher.Text)
myCommand.Parameters.Add("@AcqDate", cbAcqDate.Text)
myCommand.Parameters.Add("@AcqCost", txtAcqCost.Text)
myCommand.Parameters.Add("@Volume", txtVolume.Text)
myCommand.Parameters.Add("@ItemCategory", "Book")
myCommand.Parameters.Add("@Mode", "Available")
ra = myCommand.ExecuteNonQuery()
MessageBox.Show("New Book Record Inserted")
 
 
Catch a As Exception
MessageBox.Show(a.Message)
End Try
myConnection.Close()
myCommand.Dispose()
myConnection.Dispose()
End If
End Sub
i write this function to search a data when user press enter at textbox.
VB.NET:
Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
Dim Description, SerialNo, Publisher, Volume, Author, AcqDate, AcqCost, ItemCategory
Try
If e.KeyCode = Keys.Enter Then
connection.ConnectionString = strBuffer
connection.Open()
SQL = "SELECT * FROM MasterList WHERE SerialNo= '" & TextBox1.Text & "'or AssetNo ='" _
& TextBox1.Text & "'or ControlNo ='" & TextBox1.Text & "' or PAno='" & TextBox1.Text & "' "
SqlDtAd = New SqlDataAdapter(SQL, connection)
DS = New DataSet
SqlDtAd.Fill(DS, "MasterList")
If DS.Tables("MasterList").Rows.Count <> 0 Then
DR = DS.Tables("MasterList").Rows(0)
Description = DR("Description")
SerialNo = DR("SerialNo")
Publisher = DR("Publisher")
Author = DR("Author")
Volume = DR("Volume")
AcqDate = DR("AcqDate")
AcqCost = DR("AcqCost")
ItemCategory = DR("ItemCategory")
TextBox1.Text = SerialNo
TextBox2.Text = Description
TextBox3.Text = Author
TextBox4.Text = Publisher
TextBox5.Text = AcqDate
TextBox6.Text = AcqCost
TextBox7.Text = Volume
TextBox8.Text = ItemCategory
Else
MsgBox("No record found !")
End If
connection.Close()
SqlDtAd.Dispose()
connection.Dispose()
End If
Catch a As Exception
MessageBox.Show(a.Message)
End Try
End Sub
this is my delete function at the same form.
VB.NET:
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Try
connection.ConnectionString = strBuffer
connection.Open()
SQL = "DELETE FROM MasterList WHERE SerialNo = '" & TextBox1.Text & "'"
command = New SqlCommand(SQL, connection)
RecReturn = command.ExecuteNonQuery

connection.Close()
command.Dispose()
connection.Dispose()
MessageBox.Show("User Record has Deleted")
Catch a As Exception
MessageBox.Show(a.Message)
End Try
end sub
 
all the function is doing at the same form

this is the sample form layout. i am using <me.close> to close the form. thank you very much.
attachment.php


attachment.php
 

Attachments

  • addnewbookForm.JPG
    addnewbookForm.JPG
    56.9 KB · Views: 25
  • DeleteTab.JPG
    DeleteTab.JPG
    58.3 KB · Views: 28
your search query probably loads half a million rows into the dataset... ORs tend to be divergent rather than convergent when it comes to number of results
 
your search query probably loads half a million rows into the dataset... ORs tend to be divergent rather than convergent when it comes to number of results

but the search query will process when user press enter on the textbox. i dint call this query at form load. i just open and close the form, i dint run any process already, the memory usage oso keep increasing. i just call the query to read the server address from INI file during my form load.
 
post your project WITHOUT THE BIN OR OBJ FOLDERS in a zip file here. Ensure you include any databases and exclude any third party controls you may be using..
 
i am sorry. this few day cant upload my program yet. bcs now my office is on holiday. so i cant post the database file. Can i just post the program file without obj file and bin folder?
 
"I have a problem with my winamp, it cant play a certain MP3. I can send you a copy of my Winamp, but I cant send you the MP3"


I'll wait, until you can get the database, i think..
 
Cjard, i am sorry to let u wait so long.
my database file 60mb and my program file is 150mb. both of the file are too larger to upload into this web.
 
Impressive. How about you create a smaller example?

Incidentally.. your app is 150mb, and you complain it eats 160mb of memory?!
 
i know my program file quick big, but the memory using suppose should be fix 1. it dont fix, it alway increase when u open a form. eventhough i close tat form the memory still maintain at the same place. never mind, cjard. i try to find out the problem first. thank you very much. lol
 
Back
Top