[20 Aug 2006] Need Help Again with RemoveItem()
Posted: Sat Jun 13, 2020 5:31 pm
Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 20 Aug 2006 11:47:00 -0600
Hi,
I'm dense so still don't understand the workings of RemoveItem(). I'm trying to dynamically hold a history of the last "History" items in a table via the following idealized code. I expected that this code would keep the last five item ids. If the debug output is reviewed, however, a copy of the 4th item is somehow created and the table grows until memory runs out. Please help me understand why this happens. Thanks!!!!
Nathan
Hi,
I'm dense so still don't understand the workings of RemoveItem(). I'm trying to dynamically hold a history of the last "History" items in a table via the following idealized code. I expected that this code would keep the last five item ids. If the debug output is reviewed, however, a copy of the 4th item is somehow created and the table grows until memory runs out. Please help me understand why this happens. Thanks!!!!
Nathan
Code: Select all
History=5
tblHistory={}
function p_Add2History()
local count=listitems(tblHistory)
local junk=0
if count=history
debugprint("Count = ",history)
junk=removeitem(tblHistory,0)
endif
tblHistory[count]={}
tblHistory[count].id=count
debugprint("Before=",count,"After=",listitems(tblHistory))
for local i=0 to listitems(tblHistory)-1
debugprint(tblHistory[i].id)
next
endfunction
for j=1 to 7
p_Add2History()
next
**Debug Output from above code**
Before= 0 After= 1
0
Before= 1 After= 2
0
1
Before= 2 After= 3
0
1
2
Before= 3 After= 4
0
1
2
3
Before= 4 After= 5
0
1
2
3
4
Count = 5
Before= 5 After= 4 ** expected this would be 5,5 **
1
2
3
4 ** expected that this would be 1,2,3,4,5 **
Before= 4 After= 6 ** expected this would be 5,5 **
1
2
3
4
4
5 ** expected this would be 2,3,4,5,5 **