|
Hello,
My question is about memory leak in .NET. Let's say that i have form that loads another form that contains a number of controls(eg datagrids). Form2 does nothing. No data are bound to controls. When i run the program i observe the memory usage in the taskbar and i can see that memory increases when form2 is shown and that is acceptable. when i close the form memory remains the same and when i reopen it memory increases. as you can understand if i have a large app with many forms which using data the memory leak is huge and the app crashes after a while.
Is there a way to implement GC when the form is about to close? Is there a way to reduce memory leak?
Thank you
|
|
|
|
|
mayandi wrote: Is there a way to reduce memory leak?
This question seems to be getting asked a lot - it isn't hard to search the forums. There is a search button at the top.
Here is a link from a thread on this very topic from yesterday[^]
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
|
|
|
|
|
See this thread previous discussion[^] for a discussion on GC and complex apps with memory leaks.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
Hi everybody
I have a vb program that send instructions via OLE to an EXCEL instance to do some operations with workbooks. My question is: is there a way to attach a VB Module(but not a Class Module, just a simple module) to an open workbook @ runtime?? And if it's possilble, can I call a function contained in that module??
Thanks
TK
|
|
|
|
|
Hi Guys,
In VB.Net, how do you make a connection to an access database and use this connnection throughout the application. Also, when making the connection if we fix the path to the database(i.e. drive, folder..), then when the application is deployed on a different machine on a different drive, will this cause an issue.
With Best Regards,
Mayur
|
|
|
|
|
hi,
To connect to access database use the namespace as OLEDB instead of SQLCLIENT.
And then goahead as other connection in >net.
Oh Yes dont ever fix the drive or dir for the connection.
Rather make a string in your config file (that is provided with vb.net application) and read the path from the config file.
Config file gives you the liberty to change the settings and configuration at any time.
DD
Debasish Das(MBA), is a hardcore software solution provider, working in ESSPL (INDIA). Got 5 years of experience on various client server technologies like Visual Basic,.NET framework, Power Builder, Message Queue Server. And also posses sound knowledge in Quality Processes applied to software engineering. Quite often travels overseas to provide solutions to some fortune 100 clients.
He can be reached with mr_debasishdas@hotmail.com or debasishd@esspl.com
|
|
|
|
|
hi,
how to send some text to another machine using winsock in VB.
some small example will helpful to me.
Paritosh
|
|
|
|
|
Have you looked at the articles on this website?: http://www.codeproject.com/vb/net/#Internet
This one looks like about your search:
http://www.codeproject.com/vb/net/TinyUDP.asp
|
|
|
|
|
On executing of this line
br.Read(bytBuffer, 0, bytBuffer.Length)
We are trying to read a binary files of size 88kb , and merge all these into a single file , sometimes the application crashes on br.Read statement.
We later found out that it is a system error &H80131315& .
How can we solve this ??
|
|
|
|
|
If you put a Try..Catch block around the read does it give you more information?
'--8<------------------------
Ex Datis:
Duncan Jones
Merrion Computing Ltd
|
|
|
|
|
melvis_vaz wrote: br.Read(bytBuffer, 0, bytBuffer.Length)
My guess is that you are over-running the buffer or have not properly initialized it. As has been suggested already, encapsulate this in a Try..Catch block and extract more information from the thrown exception.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
Dim bw As BinaryWriter
Dim br As BinaryReader
Dim lFileSize As Long
Dim bytBuffer() As Byte = New Byte() {}
Dim sOutputPath As String = sFilePath.Substring(0, sFilePath.Length - 4)
Dim fsInput As New FileStream(sFilePath, FileMode.Open, FileAccess.Read)
Dim fsOutput As New FileStream(sOutputPath, FileMode.Create, FileAccess.ReadWrite)
Try
br = New BinaryReader(fsInput)
br.BaseStream.Seek(0, SeekOrigin.Begin)
lFileSize = FileSize(sFilePath)
ReDim bytBuffer(lFileSize - 1)
br.Read(bytBuffer, 0, bytBuffer.Length)
Dim MaxOut As Int32 = lFileSize - 64
ReDim btyBufferOutput(MaxOut - 1)
Dim Status As Int32 = 0, RetVal As Int32 = 0, Progress As Int32 = 0
Do
RetVal = CryptStatus(Status, Progress)
Loop While ((RetVal = 0) And (Status = 2))
bw = New BinaryWriter(fsOutput)
bw.Write(btyBufferOutput)
fsOutput.Flush()
br.Close()
fsInput.Close()
fsOutput.Close()
bw.Close()
Catch ex as Exception
Msgbox(ex.ToString)
Finally
fsOutput = Nothing
bw = Nothing
br = Nothing
fsInput = Nothing
End Try
This is the code . We have put try , catch . Also properly initialized it.
|
|
|
|
|
Where do you declare btyBufferOutput? Why do you output the contents of btyBufferOutput without putting anything in it?
---
b { font-weight: normal; }
|
|
|
|
|
The actual code is :
Dim bw As BinaryWriter
Dim br As BinaryReader
Dim lFileSize As Long
Dim bytBuffer() As Byte = New Byte() {}
Dim btyBufferOutput() As Byte = New Byte() {}
Dim sOutputPath As String = sFilePath.Substring(0, sFilePath.Length - 4)
Dim fsInput As New FileStream(sFilePath, FileMode.Open, FileAccess.Read)
Dim fsOutput As New FileStream(sOutputPath, FileMode.Create, FileAccess.ReadWrite)
Try
br = New BinaryReader(fsInput)
br.BaseStream.Seek(0, SeekOrigin.Begin)
lFileSize = FileSize(sFilePath)
ReDim bytBuffer(lFileSize - 1)
br.Read(bytBuffer, 0, bytBuffer.Length)
Dim MaxOut As Int32 = lFileSize - 64
ReDim btyBufferOutput(MaxOut - 1)
' DecryptBuffer() function is decrypting the value in bytBuffer and
' storing the decyrpted value in bytBuffer output. this is calling a third- ' party dll
DecryptBuffer(sLangaugeKey, bytBuffer, lFileSize, btyBufferOutput, MaxOut)
Dim Status As Int32 = 0, RetVal As Int32 = 0, Progress As Int32 = 0
Do
RetVal = CryptStatus(Status, Progress)
Loop While ((RetVal = 0) And (Status = 2))
bw = New BinaryWriter(fsOutput)
bw.Write(btyBufferOutput)
fsOutput.Flush()
br.Close()
fsInput.Close()
fsOutput.Close()
bw.Close()
Catch ex as Exception
MsgBox(ex.ToString)
Finally
fsOutput = Nothing
bw = Nothing
br = Nothing
fsInput = Nothing
End Try
|
|
|
|
|
I don't know if this is the reason for the error, but it's worth trying:
Don't use ReDim. There is no way of resizing an array in .NET anyway, so there is no reason to use it. Just create the arrays when you know how large it needs to be:
bytbuffer = New Byte(lFileSize)
btyBufferOutput = New Byte(MaxOut)
---
b { font-weight: normal; }
|
|
|
|
|
Try obtaining the file size and hence the buffer length by this code...
Dim fileDetails As System.IO.FileInfo = New System.IO.FileInfo(sFilePath)
lFileSize = fileDetails.Length
That will give you the filesize in bytes. I think the FileSize() property you were using returned the size in kB (??).
Trace the code in debug mode and see that the filesize is what's expected. Inspect all other variables for correctness before each line is executed and you'll find the problem.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
In the code shown ,
lFileSize = FileSize(sFilePath)
'This function is used to get the filesize
Public Function FileSize(ByVal sFileName As String) As Long
Dim fileInfo As System.IO.FileInfo
fileInfo = New FileInfo(sFileName)
Return fileInfo.Length
fileInfo = Nothing
End Function
MV
|
|
|
|
|
So... have you traced the code? What was the value for the returned filesize? Is it valid etc...?
Just giving me more code without explanation or not answering my previous questions ain't gonna get you anywhere fast.
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
-- modified at 7:27 Wednesday 11th January, 2006
|
|
|
|
|
The returned filesize is 88kb . We have encrypted binary files, we are reading this encrypted file into a buffer , and passing this buffer to dencryptbuffer() function. this is a 3rd party dll function which dencrypt the data from the buffer and stored in a output buffer.Then we are writing this output buffer to create dencrypted file.
The application works fine 4 times, but on the fifth time, the application crashes on BinaryReader.Read.
MV
|
|
|
|
|
melvis_vaz wrote: we are reading this encrypted file into a buffer , and passing this buffer to dencryptbuffer() function.
Ok, so it may be the decrypt function that's stuffing it up? Especially since you say it works the first 4 of 5 times that it's run.
Are you passing in the SAME buffer each time? Does the decrypt function destroy the input buffer in any way? Have you traced the code through five times and seen what's different on the fifth attempt?
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
The decrypt function is in a for loop and we are using Redim for the buffer , so it is intialized everytime. As the decrypt function is present in a 3rd party DLL , we do not know whether the decrypt function destroy the input buffer in any way.
MV
|
|
|
|
|
melvis_vaz wrote: The decrypt function is in a for loop and we are using Redim for the buffer , so it is intialized everytime
Not quite true. See previous posts re: ReDim(). There is no guarantee that the contents of the buffer have been zeroed.
melvis_vaz wrote: As the decrypt function is present in a 3rd party DLL , we do not know whether the decrypt function destroy the input buffer in any way.
Yes you do! That's what the debug trace is for. You inspect the buffer before and after each call to the decrypt function and see if it changes. Have you done this as I have been suggesting for the last three posts?
...Steve
"Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." (Translation: I'll show you the way, but not write the code for you.) I read that somewhere once
|
|
|
|
|
Hi guys,
I wanted to know how do we access a specific exe's instance from class library dll or any application.
The description of problem domain is as follows :
I have one VB.NET exe application which has certain functionality in it in classes. There are several instances of the same exe running in memory. I want to access specific instance and create instance of class in the exe from another client application.
Could you suggest a way to do it...
Thanks & Regards,
Birendra
Birendra
|
|
|
|
|
Input string was not in a correct format.
Line 94 seems to be the culprit but I don't know why
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 92: SqlConnection1.Open()
Line 93: Dim dreader As SqlClient.SqlDataReader
***********************************************************************
***********************************************************************
Line 94: dreader = cmdCategoriesById.ExecuteReader(CommandBehavior.SingleRow)
**********************************************************************************
**********************************************************************************
Line 95: If dreader.Read() Then
Line 96: txtCategoryName.Text = dreader(1)
Source File: c:\inetpub\wwwroot\VBNetUnleashed\WebApplication3\WebForm1.aspx.vb Line: 94
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
WebApplication3.WebForm1.ddlCategoryID_SelectedIndexChanged(Object sender,
EventArgs e) in c:\inetpub\wwwroot\VBNetUnleashed\WebApplication3\WebForm1.aspx.vb:94
System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()
Here is my code:
Private Sub ddlCategoryID_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ddlCategoryID.SelectedIndexChanged
Dim categoryid As String
categoryid = ddlCategoryID.SelectedItem.Text
cmdCategoriesById.Parameters("@categoryid").Value = categoryid
SqlConnection1.Open()
Dim dreader As SqlClient.SqlDataReader
dreader = cmdCategoriesById.ExecuteReader(CommandBehavior.SingleRow)
If dreader.Read() Then
txtCategoryName.Text = dreader(1)
txtCategoryDescription.Text = dreader(2)
End If
dreader.Close()
SqlConnection1.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSave.Click
With cmdCategoriesUpdate
.Parameters("@categoryid").Value = ddlCategoryID.SelectedItem.Text
.Parameters("@categoryname").Value = txtCategoryName.Text
.Parameters("@categorydescription").Value = txtCategoryDescription.Text
End With
SqlConnection1.Open()
cmdCategoriesUpdate.ExecuteNonQuery()
SqlConnection1.Close()
End Sub
End Class
|
|
|
|
|
The category id could not be converted to a number.
You should convert the values to the correct data type before putting them in the parameters. Also, you should specify the data type of the parameters, or the command object has to ask the database for the data types. This causes an extra round trip to the database.
---
b { font-weight: normal; }
|
|
|
|