Tcl Source Code

Artifact [2c25ee45f1]
Login

Artifact 2c25ee45f1dca82b7a66f20fab86c39b6ec1a82c:

Attachment "memarrlist" to ticket [781746ffff] added by jbeltz 2003-08-02 04:05:59.
#!/fis/mantis/common/apps/tcltk/bin/tclsh

#  Used to put a message out and wait for an enter.
proc Wait { {message "" } } {
	puts -nonewline "$message..."
	flush stdout
	gets stdin dummy
}

#  Create the initial list to use.
set element {}
for {set count 1} {$count < 100} {incr count} {
	lappend element $count
}

#  Create an array of 20000 element each with its own list element.
for {set count 1} {$count < 20000} {incr count} {
	#  Make sure to create a new list element with the list command.
	set a($count) [concat $element $count]
}

# The below is done so all the memory should be allocated before the for loop.
set myList [lsort [array names a]]
Wait "Initialized"

#  Go through the loop, but force a copy of the list from the array
foreach index $myList {
    set recordLine [concat $a($index)]
	set size [llength $recordLine]
}
Wait "Finished Loop1"

#  Go through the loop, but use the list in the array
foreach index $myList {

	# either statement causes a memory leak?
    if { 1 } {
		set recordLine $a($index)
		set size [llength $recordLine]
	} else {
		set size [llength $a($index)]
	}
}
Wait "Finished Loop2"