Deutsch   English   Français   Italiano  
<vivcol$2feip$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Christian Gollwitzer <auriocus@gmx.de>
Newsgroups: comp.lang.tcl
Subject: Re: try... query
Date: Fri, 6 Dec 2024 18:37:25 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <vivcol$2feip$1@dont-email.me>
References: <viut96$2bm0b$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 06 Dec 2024 18:37:26 +0100 (CET)
Injection-Info: dont-email.me; posting-host="76c30c27c358a777fbeb3dd149bead3a";
	logging-data="2603609"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+U/bNbKqlPB3u1UdaxBR5w0fTpX0Cddgw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6jboCIQwRlqRwrzAUCetu0xJcBE=
In-Reply-To: <viut96$2bm0b$1@dont-email.me>
Bytes: 1935

Am 06.12.24 um 14:11 schrieb Alan Grunwald:
> I'm attempting to get my head around preventing resource leaks, using 
> try and return.

I haven't worked through your code, but in C++, there is a great idiom 
called RAII - things get destroyed when the variable goes out of scope. 
This can be simulated for Tcl using a delete trace on the variable.
Using the little utils package from here: 
https://github.com/BessyHDFViewer/BessyHDFViewer/tree/main/bessyhdfviewer.vfs/lib/SmallUtils

You can do this for files:

proc something {} {
	SmallUtils::autofd fd somewfile w
	puts $fd "Text comes here"
}
# fd goes out of scope, file is closed

and for any objects that work Tk-like, giving a command back:


SmallUtils::autovar btn button .b -text "Hi"
# will destroy if btn goes out of scope
# by "rename .b {}"


Of course, this is not perfect, it will fail if you copy the variable 
somewhere else, but often times it is good enough.

                Christian