Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Out of memory on loStringBuilder.ToString()
Message
From
06/06/2011 16:49:49
 
 
To
06/06/2011 16:38:14
General information
Forum:
ASP.NET
Category:
Troubleshooting
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01513090
Message ID:
01513213
Views:
29
I have no idea how big your string is, but I can see how a large enough string might eat up memory. Perhaps you can have an overloaded CreateFileEncoding() method that takes a StringBuilder instead of a string. That way, you don't utilize .ToString() until you're in the process of actually writing it out to a file
loStreamWriter.Write(tcStringBuilder.ToString())
Would that work ok for you?

~~Bonnie


>>Is the exception occurring at loStringBuilder.ToString() or is it occuring somewhere in the CreateFileEncoding() method when the method attempts to do something with the string?
>
>Here is CreateFileEncoding():
>
>
>        ' Create a file by passing an encoding
>        ' expC1 String
>        ' expC2 File
>        ' expC3 Encoding
>        ' expL1 If we log the error if the file cannot be deleted
>        Public Function CreateFileEncoding(ByVal tcString As String, ByVal tcFile As String, _
>         ByVal tcEncoding As System.Text.Encoding, ByVal tlLogError As Boolean) As Boolean
>            Dim llSuccess As Boolean = False
>            Dim lnCounter As Integer = 0
>            Dim lnDelay As Integer = 250
>            Dim lnRetry As Integer = 8
>            Dim loFileStream As FileStream
>            Dim loStreamWriter As IO.StreamWriter
>
>            For lnCounter = 1 To lnRetry
>
>                Try
>                    loFileStream = New FileStream(tcFile, FileMode.Create)
>                    loStreamWriter = New StreamWriter(loFileStream, tcEncoding)
>                    loStreamWriter.Write(tcString)
>                    loStreamWriter.Close()
>                    loFileStream.Close()
>                    llSuccess = True
>                    Exit For
>
>                Catch loError As Exception
>
>                    ' If we have not reached the maximum tries of 8, we retry
>                    If lnCounter < 8 Then
>
>                        ' Wait for a timeout before retrying
>                        System.Threading.Thread.Sleep(lnDelay)
>
>                        Continue For
>                    End If
>
>                    ' If we log the error
>                    If tlLogError Then
>
>                        ' Get the proper definition as per the current scope
>                        If oProcess Is Nothing Then
>                            oApp.ErrorSetup(loError)
>                        Else
>                            oProcess.ErrorSetup(loError)
>                        End If
>
>                    End If
>
>                End Try
>
>            Next
>
>            Return llSuccess
>        End Function
>
>
>So, it happens at the loStringBuilder.ToString() location.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform