#!/usr/local/bin/rune -x # # Test heap storage. Rune does not garbage collect loops... that is # considered a run time error (which we will eventually detect). Rune # will track references and delete heap objects recursively. It is # recommended that you not rely on this for long singly-linked lists # because you may run out of stack. Intead you should NULL the next # pointer out manually. # # This example defaults to recursively cleaning up after your list. # If you change the 'i' loop to go to, say, 100000, and the (i == 30) # to be (i == 80000), you may see the stack overflow. import "sys"; import ; alias stdio.File *stdout = stdio.stdout; class Test { Test *next; int index; } int main(int ac, char **av) { Test *item; int i; for (i = 0; i < 1000000; ++i) { item.new(); item->index = i; fubar(item); } } void fubar(Test *item) { global Test *base; global Test **last = &base; global int count = 0; item = bleh(item); *last = bleh(item); last = &item->next; if (item->index > 50000) { base = base->next; } if (item->index % 10000 == 0) stdout->show(item->index, (int)(item - base)); } Test * bleh(Test *next) { return(next); }