When you use a function that returns an array as a parameter to the UBound or LBound functions, the memory allocated for the array is not released.
The array is copied to temporary return storage, but the temporary storage is not released until the application ends.
To avoid this problem, assign the return value to a local variable before using UBound or LBound. For example:
vntReturn = ArryFunc()
iAryLen = UBound(vntReturn)
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
Steps to Reproduce Behavior
- Create a New Standard EXE project in Visual Basic. Form1 is created by default.
- Add a CommandButton (Command1) to Form1.
- Add the following code to Form1:
Public Sub Command1_Click()
iAryLen = UBound(ArryFunc())
- Add a standard Module to the project and add the following code:
Public Function ArryFunc() as Long ()
Dim x(100000) as Long
ArryFunc = x
- Run the project.
Id. de artículo: 197190 - Última revisión: 05/12/2003 - Revisión: 1