-
Feb 6th, 2018, 06:06 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to release memory used by an array of UDTs containing strings?
What is the correct way to release all of the memory used by an array of UDTs when the UDT members contain variable length strings? Is Erase enough? Or do I need to clear out the strings in each UDT?
For example...
Code:
Private Type Person
FirstName As String
LastName As String
End Type
Private People() As Person
Private Sub Form_Load()
Dim i As Long
ReDim People(1 To 100)
For i = 1 To 100
With People(i)
.FirstName = "Joe"
.LastName = "Smith"
End With
Next
'//cleanup
'...is this necessary?
For i = 1 To 100
With People(i)
.FirstName = vbNullString
.LastName = vbNullString
End With
Next
'...or is this all I need to do?
Erase People
End Sub
-
Feb 6th, 2018, 10:10 PM
#2
Fanatic Member
Re: How to release memory used by an array of UDTs containing strings?
Erase should work just fine.
To test use erase, and then see if you can access the info in the UDT.
-
Feb 7th, 2018, 05:34 AM
#3
Re: How to release memory used by an array of UDTs containing strings?
Yes, Erase should be enough to erase.
But the question is: what are you AAraya worried about?
Are you looking for a secure erase where the names of the persons are not left somewhere in memory after erase?
Are you worried about how much RAM memory your program uses?
-
Feb 7th, 2018, 09:38 AM
#4
Thread Starter
Hyperactive Member
Re: How to release memory used by an array of UDTs containing strings?
Originally Posted by Eduardo-
Yes, Erase should be enough to erase.
But the question is: what are you AAraya worried about?
Are you looking for a secure erase where the names of the persons are not left somewhere in memory after erase?
Are you worried about how much RAM memory your program uses?
Sorry for being unclear in my question.
I am looking to free up all BSTR memory used by my program.
-
Feb 7th, 2018, 09:55 AM
#5
Re: How to release memory used by an array of UDTs containing strings?
-
Feb 7th, 2018, 10:09 AM
#6
Re: How to release memory used by an array of UDTs containing strings?
I'll second (or third or fourth) that. Erase is sufficient. Just think of it as recursion or nesting. If VB6 didn't get it correct, we would have heard about it long ago. The same would be true for any Objects in your UDT array or any other sub-arrays in your UDT array.
EDIT1: The Objects will implicitly have their internal counter decremented (and un-instantiated if it went to zero).
EDIT2: The only true bug I know of when UDT arrays is that, when you pass them, the VB6 p-code interpreter and machine-code compiler don't check for "Type Mismatch". In other words, when you pass these things, they might be declared as one type of UDT and then "caught" as another type of UDT (possibly of different length). If it's not a UDT array, all works as it should (reporting Type Mismatches).
Last edited by Elroy; Feb 7th, 2018 at 10:16 AM.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|