Just checking in to see the status on this problem. I think this is the reason behind the leak in my game.
I tried all the following ways to cleanly kill an array with no luck:
undim(tempArray())
empty array tempArray()
for i = array count(tempArray()) to 0 step -1 : array delete element tempArray(), i : next i
I am making a card game, and each card is a UDT with several strings. Each card gets moved from one global array to another based on its position on the board/deck, so every time a card moves and is deleted from one array and added to another, I leak. It is really obvious later in the game when I have several cards out.
It would be rather difficult for me to implement this "free string()" thing due to the shear number of places where an array element is deleted.
Edit: Just ran a simple test. UDTs aren't the only problem, at least for me. The following keep leaking memory as well. It is how I handle debug information. Throughout the game I add strings to a global array, and each sync I put the strings on the screen (I use the d3d_text command, not print, but changed it so you dont need DLLs). The following contains a string array, no UDT, and it still leaks;
REM Project: TestStringMem
REM Created: 1/1/2009 2:50:53 PM
REM
REM ***** Main Source File *****
REM
GLOBAL DIM Screen_Debug$(-1)
create bitmap 1, screen width(), screen height()
set current bitmap 1
sync on
sync rate 0
do
cls 0
Screen_Debug_Add(str$(timer()))
Screen_Debug_Add(get date$())
Screen_Debug_Add(str$(system smem available()))
Update_Screen()
loop
function Update_Screen()
if array count(Screen_Debug$()) > -1
for i = ARRAY COUNT(Screen_Debug$()) to 0 step -1
print Screen_Debug$(i) : ` Changed from d3d_text
` UNCOMMENT the next line and leak is gone
` Screen_Debug$(i) = free string$()
array delete element Screen_Debug$(), i
next i
endif
copy bitmap 1, 0
sync
endfunction
function Screen_Debug_Add(txt$)
array insert at bottom Screen_Debug$()
Screen_Debug$(array count(Screen_Debug$()))=txt$
endfunction