Hi,
What puzzles me is that I often read that Tcl does not release memory.
But according to the tasks manager ( Windows 11), with an accuracy of 0.1 Go, "unset" perfectly release memory, while "namespace delete" makes nothing.
So I wonder if :
1) Can it be an Ashok's "magic" spell (binaries are from him) ?
2) Is it normal that what can be done in global name space cannot
be done in another namespace ? ( I have also added some"array unset"
or "unset -nocomplain" to eradicate any possibility in
::struct::matrix::_destroy , wich I give below the original code)
For the brave I have an extra question :
In the matrix package there are 18 "catch {unset xyz}", if I replace
them by "unset -nocomplain xyz", the execution time is reduced
by a factor 8-10. Unless it has been forgotten after the apparition
of "-complain", could be there a trick to use catch / unset, in the
place of unset -nocomplain ?
Best regards, Olivier.
oooooooooo START ::struct::matrix::_destroy oooooooooooooo
proc ::struct::matrix::_destroy {name} {
variable ${name}::link
Unlink all existing arrays before destroying the object so that
we don't leave dangling references / traces.
foreach avar [array names link] {
_unlink $name $avar
}
namespace delete $name
interp alias {} $name {}
}
oooooooooo END ::struct::matrix::_destroy oooooooooooooo
oooooooooo START MEMORY TEST oooooooooooooo
# 1) UNSET USAGE IN GLOBAL SPACE
global localDir ; set localDir [file dirname [info script]]
source [ file join "$localDir" matrix.tcl ]
for { set i 0 } { $i < 5 } { incr i } {
set _BIG [ lrepeat 500000000 "dummy" ]
unset _BIG
}
tk_messageBox -title "Memory Test" -message "Check mem 1 !"
# 2) UNSET USAGE IN A PROCEDURE
proc testmem {} {
set _BIG [ lrepeat 500000000 "dummy" ]
}
for { set i 0 } { $i < 5 } { incr i } {
testmem
}
tk_messageBox -title "Memory Test" -message "Check mem 2 !"
# 3) NAMESPACE DELETE
set _BIG [ lrepeat 5000000 "dummy" ]
# if {[namespace exists _matrix_in]} {
# _matrix_in destroy
# }
::struct::matrix _matrix_in
_matrix_in add columns 1
_matrix_in add rows [ llength $_BIG ]
_matrix_in set column 0 $_BIG
_matrix_in destroy
# an extra delete !
namespace delete ::struct::matrix
tk_messageBox -title "Memory Test" -message "Check mem 3 !"
exit
oooooooooo END MEMORY TEST oooooooooooooo
What puzzles me is that I often read that Tcl does not release memory.
But according to the tasks manager ( Windows 11), with an accuracy of 0.1 Go, "unset" perfectly release memory, while "namespace delete" makes nothing.
On 9/9/2025 3:02 AM, Olivier wrote:
What puzzles me is that I often read that Tcl does not release memory.
But according to the tasks manager ( Windows 11), with an accuracy of 0.1 Go,
"unset" perfectly release memory, while "namespace delete" makes nothing.
How are you measuring the current memory? Since it seems you are on windows, then there are several items this could be. I don't think tcl can release virtual memory allocated back to the operating system by shrinking the process at the end. And it's almost certain that it can't do that if the memory freed up is somewhere in the middle of the heap. In this case, it would put the freed up memory into a list of free memory, to be reused on the next allocation.
In windows, there is also working set, which is the amount of physical memory being used. This can shrink, even if you don't free up any virtual memory. The working set is managed completely by the OS, although there may be some system calls that can increase or decrease that. But that's not the same as the virtual memory space.
I don't think windows 11 has changed any of this, but then anything is possible.
others may answer in more detail, no time, some remarks:
It is not true, that Tcl never releases memory.
....
Then, the history package still keeps a copy of the data and it is not >released.
Absolutly YES, but others have the magic too.
So, the release moment may be tricky.
If you delete a namespace: are you sure, nothing has a copy of your huge data?
I think, the catch version is slower in the error case. It saves the
call stack and the error message in global variables.
How are you measuring the current memory?
That said, I only use Ashok's binaries, I can try with other distributions
to see if "namespace" has a concern in memory management ?
Am 10.09.2025 um 10:27 schrieb Olivier:
That said, I only use Ashok's binaries, I can try with other distributions to see if "namespace" has a concern in memory management ?
I don't think it is the distribution.
Ashoks binaries are build using MS-VS 2022. This should be ok.
Better craft an example and post it here.
Am 10.09.2025 um 10:27 schrieb Olivier:
That said, I only use Ashok's binaries, I can try with other distributions to see if "namespace" has a concern in memory management ?
I don't think it is the distribution.
Ashoks binaries are build using MS-VS 2022. This should be ok.
Better craft an example and post it here.
Harald Oehlmann <wortkarg3@yahoo.com> posted:
Am 10.09.2025 um 10:27 schrieb Olivier:
That said, I only use Ashok's binaries, I can try with other distributions >>> to see if "namespace" has a concern in memory management ?
I don't think it is the distribution.
Ashoks binaries are build using MS-VS 2022. This should be ok.
Better craft an example and post it here.
Harald,
(Once again the same post, it seemed to have a problem this morning in Newsgrouper)
Your suggestion made me wrote a test with "set _BIG [ lrepeat 500000000 "dummy" ]"
inside a namespace. And by deleting the namespace, the memory was releaed ! It is
definitively a problem from "matrix" package that I have to solve.
I wish you a nice end of day,
Olivier.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,072 |
Nodes: | 10 (0 / 10) |
Uptime: | 129:31:44 |
Calls: | 13,772 |
Files: | 186,986 |
D/L today: |
284 files (126M bytes) |
Messages: | 2,429,801 |