jj2007 wrote:fzabkar wrote:... will setting the string to null return its memory to the heap?
Yes, using msvcrt.free, which in turn uses
RtlFreeHeap
I know it's difficult to use an assembly level debugger, but what I wrote is the truth, and you won't get the truth from FRE(). However, if you insert a Sleep as shown below, you can get closer to the truth without using the debugger:
Code: Select all
Dim sBigString As String
Dim lenfil As ULong
lenfil = 100 * 1000 * 1000
print fre() \ (1000 * 1000)
sBigString = Space( lenfil )
print fre() \ (1000 * 1000)
sBigString = ""
Sleep ' wait a second
print fre() \ (1000 * 1000)
Sleep
Typical output:
Here is the relevant code under the hood, compiled with Gcc-32 (Gas and FB 64 are very similar):
Code: Select all
CPU Disasm
Address Hex dump Command Comments
004020D0 Ú$ 53 push ebx ; TmpFb.004020D0(guessed Arg1)
004020D1 ³. 83EC 18 sub esp, 18
004020D4 ³. 8B5C24 20 mov ebx, [esp+20]
004020D8 ³. 85DB test ebx, ebx
004020DA ³. 74 22 jz short 004020FE
004020DC ³. 8B03 mov eax, [ebx] ; get the pointer to the string memory
004020DE ³. 85C0 test eax, eax
004020E0 ³. 74 1C jz short 004020FE ; if zero, don't free it
004020E2 ³. 890424 mov [esp], eax ; Úmemblock
004020E5 ³. E8 DE270000 call <jmp.&msvcrt.free> ; ÀMSVCRT.free, call RtlFreeHeap
004020EA ³. C703 00000000 mov dword ptr [ebx], 0 ; mark deleted
004020F0 ³. C743 04 00000000 mov dword ptr [ebx+4], 0
004020F7 ³. C743 08 00000000 mov dword ptr [ebx+8], 0
004020FE ³> 83C4 18 add esp, 18
00402101 ³. 5B pop ebx
00402102 À. C2 0400 retn 4