Artifacts Associated With Ticket 0e48e053283e6fb8
Ticket change [81c6496a98] (rid 162086) by anonymous on 2018-03-26 16:21:37:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The manual page for the [apply] command describes the semantics of the command with a pure Tcl procedure. However, that implementation would never clean up created procedures, leading to memory leaks where the [apply] command is parameterised in, say, a loop. It would be good to mention that, unlike the pure Tcl description, [apply] commands are cleaned up with the reference count system just as with any other Tcl values. Alternatively the semantics code could be altered to destroy the newly created command before [return].
- foundin initialized to: "8.6"
- is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "0dfe2e6aa820af3598e203fec901fc46f1ba3c95"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "16. Commands A-H"
- title initialized to: "Clarify that [apply] functions are cleaned up"
- type initialized to: "Bug"
Ticket change [69fa1ebcec] (rid 162096) by sebres on 2018-03-26 20:02:35:
- icomment:
1. If you meant the interim proc "$name" created inside example in the manual page - it will be already removed. Possibly you overlooked one thing, the example does additionally - the clean-up with "rename [lindex [info level 0] 0] {}", which deletes itself implicitly before it returns from each "apply-proc". 2. In part where the manual page describes the semantics "with a pure Tcl procedure" it meant just really semantic only - so it is similar as it acts like this proc. So if you meant any other case, like create another proc inside... The case where something evaluable (inclusive the command "apply") creates a "sub" proc inside of its body, is equivalent to any other script-level bodies where proc will be created (tcl does not have scope-bound proc's at all, so never implicit removed). So it means - the proc's created from everywhere are always persistent (until removed using `rename $name {}`. And body of apply-lambda does not different compared to any other evaluated tcl-body. This is not a leak (despite the proc inside will be normally always overwritten, if same name used). So in following example both are almost equivalent: <pre><code> proc test {a b} { proc log_params {args} {puts "execute [info level [info level]]"} log_params a $a b $b } test A B set lambda {{a b} { proc log_params {args} {puts "execute [info level [info level]]"} log_params a $a b $b }} apply $lambda A B </code></pre> In both cases the proc is created inside body (note it's compiled only once because of tcl-jit-compiler). Thus could you explain firstly which of both cases did you meant? - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Invalid"
- status changed to: "Pending"
- icomment:
Ticket change [127409bdcd] (rid 258121) by serhiy.storchaka on 2026-10-15 11:29:05:
- icomment: "Closing: answered above."
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"
Ticket change [0fa807782e] (rid 259925) by serhiy.storchaka on 2026-10-22 17:19:26:
- closedate changed to: "2461328.9785312153"
- closer changed to: "serhiy.storchaka"
- login: "serhiy.storchaka"