12-07-2022, 10:13 PM
(12-07-2022, 08:18 PM)bplus Wrote:Quote:Dammit! I was just about to use that as my signature. Now I have to come up with something else. Too bad Steve is busy!
"So old I knew better once but forgot."
BTW Minerva was hinting at a memory leak if start Dynamic arrays in subs... does the above test for that?
This is one of those things that is easy to test for and disprove.
Code: (Select All)
_Title "MemCheck"
Print "Open your Windows Task Manager and find the memory usage for this program."
Print "This is the amount of memory you're using prior to a call to foo."
Print
Print "Press ANY KEY..."
Sleep
foo
Print
Print "And this is how much memory you're using after exiting foo."
Print "Press ANY KEY..."
Sleep
Sub foo
Dim array(1 To 1000) As String * 1000000 '1 million bytes per string element, with 1000 elements = approximately 1GB of memory
For i = 1 To 1000
array(i) = String$(1000, "*")
Next
Print
Print "This is how much memory you're using within foo!"
Print "Press ANY KEY..."
Sleep
End Sub
Run it, open Task Manager... Your program will use about 50MB of memory. Hit any key, you go into SUB foo, and now are using over 1GB of memory. Hit any key, exit foo, and that memory is now freed. You're now back down to using the same 50MB of memory as previously.
No memory leak here.