Need help to find the memory filler...
I have an example where i use a function returning a Collection object.
Code:
Public Sub Main()
Dim myColl As Collection
Set myColl = getColl2
MsgBox myColl.Item(1)
End Sub
Function getColl() As Collection
Set getColl = New Collection
getColl.Add "something"
End Function
Function getColl2() As Collection
Dim A As New Collection
A.Add "something"
Set getColl2 = A
Set A = Nothing
End Function
Both functions will return the same object, but when will the object cease to exist in memory?
I am experiencing out-of-memory problems with my code.
My understanding of SET and NEW:
Using SET actually sets a pointer to the object. It doesn't copy its contents. Using the NEW creates a new instance of the object and the SET sets a pointer to it.
Will VBs internal garbage can take care of the object when it is no longer pointed at, or will it stay there until the program exits?
The function getColl() creates an instance of the Collection object, but will the object ever get removed from memory, when it never gets a getColl2 = nothing ?
Anyone know an ultimate routine of some sort that can garbage anything created from the current program and that is no longer in use in memory?
I need to find the memory-filler in my code, and the only uncertain factors are the Collection object described above, and the use of the CopyMemory API:
[CODE]
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpvDest As Any, _
lpvSource As Any, _
ByVal cbCopy As Long)
Sub MySub()
Dim b(1 To 10) As Byte
CopyMemory b(1), ByVal StringPointerFromAnAPI, 10
For i = 1 To 10
Debug.Print Chr(b(i)); 'Prints the string to debug.
Next
End Function
[CODE]