Re: Memory Leak in VB6 with strings and UDTs
- From: goodhart <goodhart@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 6 Sep 2006 14:09:02 -0700
Thank you.
OK, I tried to clarify my question, and to simplify my code (I left the
entire code at the end off and just included snippets of the important
stuff). Let me try again
I have found what I think is a memory leak at the core of Visual Basic 6,
either that or something I don’t understand.
I cannot list my exact code because of security so have created a simple
example that mocks what we do. I show some excerpts from that below. I have
a UDT array, myudt, which contains another UDT array, ABtype, which has a
string field called BString1.
When, in a loop over my arrays, I set BString1 to an element of an array,
bytearray, which = 111, this seems to cause a memory leak. I believe there
is a memory leak because the MS perfmonitor shows “Private Bytes” rising
about 5 MB overnight.
I have tried casting the number to a string with CStr but that doesn't help
at all. I think making the string field an integer, or a fixed length string
prevents the problem, but does anybody know why this happens. It seems like a
memory leak within the core of VB 6.
If I change BString to an integer the leak goes away.
--------------------
Here are the important definitions (from a form)
Private Type B
‘ Using this defn as string leaks.
BString1 As String
' This does NOT leak
‘’’’’BString1 As Integer
' This does NOT leak
'’’’’BString1 As String * 5
End Type
Private Type myUDTA
ABtype(1 To 1000) As B
End Type
Const MSIZE As Long = 1000
Dim myudt(1 To 1000) As myUDTA
Dim bytearray(1 To 1000) As Byte
The field of concern is the BString1 above in the B UDT.
In a timer I call the following:
....
Call f1(bytearray)
End Sub
bytearray is an array of bytes all = 111
Public Function f1(ba() As Byte) As Boolean
Dim i As Integer
Dim k As Integer
Dim tempstr As String
For i = 1 To MSIZE
For k = 1 To MSIZE
‘ It appears that the statement below causes memory to leak.
myudt(i).ABtype(k).BString1 = ba(i)
'''''''''''''tempstr = ba(i) ' This did not leak!!!!!
Next k
Next i
End Function
"Michael C" wrote:
"goodhart" <goodhart@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message.
news:506A3F88-0993-404A-8BD2-0CAB83F93296@xxxxxxxxxxxxxxxx
I am using VB6 in Visual Studio.
Our application seems to leak memory. I created a simple example to
illustrate the problem.
It basically involves setting a string field of a UDT within a UDT to some
number (a byte but the same has happened with ints). When I do that I
see
a memory leak over time. I have tried casting the number to a string with
CStr but that doesn't help at all. I think making the string field an
integer, or a fixed length string prevents the problem, but does anybody
know
why this happens. It seems like a memory leak within the core of VB 6.
You really need to simplify the sample code you posted.
Michael
- Follow-Ups:
- Re: Memory Leak in VB6 with strings and UDTs
- From: Michael C
- Re: Memory Leak in VB6 with strings and UDTs
- From: Michael C
- Re: Memory Leak in VB6 with strings and UDTs
- References:
- Memory Leak in VB6 with strings and UDTs
- From: goodhart
- Re: Memory Leak in VB6 with strings and UDTs
- From: Michael C
- Memory Leak in VB6 with strings and UDTs
- Prev by Date: Re: Access of shared member, constant member, enum member or nested type through an instance problem
- Next by Date: Re: List Forms (Odd Request)
- Previous by thread: Re: Memory Leak in VB6 with strings and UDTs
- Next by thread: Re: Memory Leak in VB6 with strings and UDTs
- Index(es):
Relevant Pages
|