Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"Stupidity, like virtue, is its own reward" -- William E. Davidsen


devel / comp.lang.tcl / Adding dictionaries to list, leaks ?

SubjectAuthor
* Adding dictionaries to list, leaks ?Anatoly Torchinskiy
+- Adding dictionaries to list, leaks ?rene
`* Adding dictionaries to list, leaks ?heinrichmartin
 `- Adding dictionaries to list, leaks ?Anatoly Torchinskiy

1
Adding dictionaries to list, leaks ?

<4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12894&group=comp.lang.tcl#12894

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ad4:4ba1:0:b0:67a:3852:2883 with SMTP id i1-20020ad44ba1000000b0067a38522883mr364604qvw.12.1701315215188;
Wed, 29 Nov 2023 19:33:35 -0800 (PST)
X-Received: by 2002:a0c:c581:0:b0:67a:3897:e6a0 with SMTP id
a1-20020a0cc581000000b0067a3897e6a0mr320270qvj.9.1701315214994; Wed, 29 Nov
2023 19:33:34 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 29 Nov 2023 19:33:34 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=157.131.170.149; posting-account=HLaB7woAAACz7mImFkpW_kmbWo7RiF2T
NNTP-Posting-Host: 157.131.170.149
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com>
Subject: Adding dictionaries to list, leaks ?
From: link13@gmail.com (Anatoly Torchinskiy)
Injection-Date: Thu, 30 Nov 2023 03:33:35 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2011
 by: Anatoly Torchinskiy - Thu, 30 Nov 2023 03:33 UTC

I have code that is leaking, I been trying to figure out what I am doing wrong. I created a test example and I am about to reproduce in tclsh

set holder {}

for {set i 0} {$i < 1144195} {incr i} {
set attr [dict create]
set all_keys {"X" "P" "A" "B" "T" "Y" "E" "W" "B"}
foreach key $all_keys {
dict set attr $key [expr int(rand()*20)]
}
lappend holder $attr
}

This eats ~2GB of RAM, using Tcl 8.5. If I then do set holder {} , after which in my head would release the holder object and all of its things, instead I see Tcl still using that ram and not letting go. What am I doing wrong here? I have similar example I did in Python and the moment I set holder in Python to None, everything is freed, but in Tcl I cant see to actually get my memory back.

I am on mac btw, not sure if this would do anything.

Thanks,
Anatoly

Re: Adding dictionaries to list, leaks ?

<f47a9308-22a3-4b18-b42c-9abdd31579c7n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12896&group=comp.lang.tcl#12896

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:622a:410:b0:423:7a49:24d4 with SMTP id n16-20020a05622a041000b004237a4924d4mr948775qtx.5.1701330017254;
Wed, 29 Nov 2023 23:40:17 -0800 (PST)
X-Received: by 2002:a05:6214:140c:b0:67a:17f7:8835 with SMTP id
pr12-20020a056214140c00b0067a17f78835mr522775qvb.10.1701330016972; Wed, 29
Nov 2023 23:40:16 -0800 (PST)
Path: i2pn2.org!i2pn.org!news.niel.me!glou.org!news.glou.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Wed, 29 Nov 2023 23:40:16 -0800 (PST)
In-Reply-To: <4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=212.243.175.74; posting-account=cY1uRgoAAAD1PpfCHRSABChlMQs7_rU7
NNTP-Posting-Host: 212.243.175.74
References: <4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f47a9308-22a3-4b18-b42c-9abdd31579c7n@googlegroups.com>
Subject: Re: Adding dictionaries to list, leaks ?
From: r.zaumseil@gmail.com (rene)
Injection-Date: Thu, 30 Nov 2023 07:40:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: rene - Thu, 30 Nov 2023 07:40 UTC

Anatoly Torchinskiy schrieb am Donnerstag, 30. November 2023 um 04:33:37 UTC+1:
> I have code that is leaking, I been trying to figure out what I am doing wrong. I created a test example and I am about to reproduce in tclsh
>
> set holder {}
>
> for {set i 0} {$i < 1144195} {incr i} {
> set attr [dict create]
> set all_keys {"X" "P" "A" "B" "T" "Y" "E" "W" "B"}
> foreach key $all_keys {
> dict set attr $key [expr int(rand()*20)]
> }
> lappend holder $attr
> }
>
>
> This eats ~2GB of RAM, using Tcl 8.5. If I then do set holder {} , after which in my head would release the holder object and all of its things, instead I see Tcl still using that ram and not letting go. What am I doing wrong here? I have similar example I did in Python and the moment I set holder in Python to None, everything is freed, but in Tcl I cant see to actually get my memory back.
>
> I am on mac btw, not sure if this would do anything.
>
> Thanks,
> Anatoly
Afaik tcl is maintaining an own list of used memory and will reuse it.
Just put your code in a proc and run it. The holder var is then local and will be deleted at the end of the proc.
The memory will grow in the first call and then stay nearly the same in further calls.

HTH
rene

Re: Adding dictionaries to list, leaks ?

<b784ee2b-d30b-4581-b669-e11ba8534873n@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12900&group=comp.lang.tcl#12900

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:14e6:b0:67a:621e:45ba with SMTP id k6-20020a05621414e600b0067a621e45bamr244240qvw.8.1701381720540;
Thu, 30 Nov 2023 14:02:00 -0800 (PST)
X-Received: by 2002:a05:6a00:acd:b0:6c6:9f26:3a00 with SMTP id
c13-20020a056a000acd00b006c69f263a00mr6555480pfl.2.1701381720281; Thu, 30 Nov
2023 14:02:00 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Thu, 30 Nov 2023 14:01:59 -0800 (PST)
In-Reply-To: <4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.226.230; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.226.230
References: <4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b784ee2b-d30b-4581-b669-e11ba8534873n@googlegroups.com>
Subject: Re: Adding dictionaries to list, leaks ?
From: martin.heinrich@frequentis.com (heinrichmartin)
Injection-Date: Thu, 30 Nov 2023 22:02:00 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1752
 by: heinrichmartin - Thu, 30 Nov 2023 22:01 UTC

On Thursday, November 30, 2023 at 4:33:37 AM UTC+1, Anatoly Torchinskiy wrote:
> I have code that is leaking, I been trying to figure out what I am doing wrong. I created a test example and I am about to reproduce in tclsh

Do you have tclreadline in use? If so, the history could be the culprit holding its own copy of Tcl objects.
You could cross-check the refcount of $holder with ::tcl::unsupported::representation before resetting it to empty.

Re: Adding dictionaries to list, leaks ?

<d45baabc-5600-4ed6-81a8-d4bf1d7876aen@googlegroups.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=12911&group=comp.lang.tcl#12911

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:20d2:b0:77f:1933:3cad with SMTP id f18-20020a05620a20d200b0077f19333cadmr8413qka.9.1701727128366;
Mon, 04 Dec 2023 13:58:48 -0800 (PST)
X-Received: by 2002:a05:620a:8d1:b0:77d:8601:3eb6 with SMTP id
z17-20020a05620a08d100b0077d86013eb6mr9634qkz.0.1701727128172; Mon, 04 Dec
2023 13:58:48 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 4 Dec 2023 13:58:47 -0800 (PST)
In-Reply-To: <b784ee2b-d30b-4581-b669-e11ba8534873n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a09:bac3:655a:28:0:0:4:2ff;
posting-account=HLaB7woAAACz7mImFkpW_kmbWo7RiF2T
NNTP-Posting-Host: 2a09:bac3:655a:28:0:0:4:2ff
References: <4ed80ef3-8485-4070-86f9-cc172ec09ebcn@googlegroups.com> <b784ee2b-d30b-4581-b669-e11ba8534873n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d45baabc-5600-4ed6-81a8-d4bf1d7876aen@googlegroups.com>
Subject: Re: Adding dictionaries to list, leaks ?
From: link13@gmail.com (Anatoly Torchinskiy)
Injection-Date: Mon, 04 Dec 2023 21:58:48 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2608
 by: Anatoly Torchinskiy - Mon, 4 Dec 2023 21:58 UTC

On Thursday, November 30, 2023 at 2:02:03 PM UTC-8, heinrichmartin wrote:
> On Thursday, November 30, 2023 at 4:33:37 AM UTC+1, Anatoly Torchinskiy wrote:
> > I have code that is leaking, I been trying to figure out what I am doing wrong. I created a test example and I am about to reproduce in tclsh
> Do you have tclreadline in use? If so, the history could be the culprit holding its own copy of Tcl objects.
> You could cross-check the refcount of $holder with ::tcl::unsupported::representation before resetting it to empty.

You are correct putting it in a proc:

proc test {} {
set holder {}

for {set i 0} {$i < 1144195} {incr i} {
set attr [dict create]
set all_keys {"X" "P" "A" "B" "T" "Y" "E" "W" "B"}
foreach key $all_keys {
# dict set attr $key [expr int(rand()*20)]
dict set attr $key "a"
}
lappend holder $attr
set attr {}
}
}

and then calling test multiple times, doesnt just add memory, but I also never reclaim memory. This makes it seem like memory will just always grow and it will never get reclaimed which is a bit weird. Yes that memory could be re-used but in my situation I expect to have this object as transient, so I would like that memory to actually be gone.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor