Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

If God had intended Man to program, we'd be born with serial I/O ports.


devel / comp.lang.tcl / Re: Understanding Tcl memory management of list created in C

SubjectAuthor
* Understanding Tcl memory management of list created in CGertjan
+- Understanding Tcl memory management of list created in CRich
+* Understanding Tcl memory management of list created in CRobert Heller
|`* Understanding Tcl memory management of list created in CRalf Fassel
| `- Understanding Tcl memory management of list created in CHarald Oehlmann
`* Understanding Tcl memory management of list created in Cheinrichmartin
 `* Understanding Tcl memory management of list created in CGertjan
  `* Understanding Tcl memory management of list created in Cheinrichmartin
   `* Understanding Tcl memory management of list created in CGertjan
    `* Understanding Tcl memory management of list created in CRalf Fassel
     `* Understanding Tcl memory management of list created in CHarald Oehlmann
      `- Understanding Tcl memory management of list created in CGertjan

1
Understanding Tcl memory management of list created in C

<fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9876&group=comp.lang.tcl#9876

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:620a:19a6:b0:6ee:d3d6:6b03 with SMTP id bm38-20020a05620a19a600b006eed3d66b03mr23624900qkb.376.1666640090706;
Mon, 24 Oct 2022 12:34:50 -0700 (PDT)
X-Received: by 2002:a05:620a:460f:b0:6ee:97b4:d35e with SMTP id
br15-20020a05620a460f00b006ee97b4d35emr25032509qkb.71.1666640090538; Mon, 24
Oct 2022 12:34:50 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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, 24 Oct 2022 12:34:50 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=155.190.0.10; posting-account=2h3mKAoAAAC6cHMkjCEBGx_FLAoEMKyZ
NNTP-Posting-Host: 155.190.0.10
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
Subject: Understanding Tcl memory management of list created in C
From: ghof...@gmail.com (Gertjan)
Injection-Date: Mon, 24 Oct 2022 19:34:50 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3527
 by: Gertjan - Mon, 24 Oct 2022 19:34 UTC

Hello,

I spent a painful weekend trying to make more sensible Tcl list from data we generate in a C extension and to understand whether or not I am creating a memory leak. The return to the user is a List of List - pairs of time and ADC data in fact.

I could replicate the actual code but I think the pseudo version will do. Its typical I think.

INT32 GetMyData (ClientData clientdata, Tcl_Interp *interp, INT32 argc, const CHAR *argv[])

Loop over N data elements:
Tcl_Obj *pSubList = Tcl_NewListObj(0,NULL);

Now put Time and a Float into pSubList using two calls to
TclListObjAppendElement(interp, pSubList,....);

//copy the sublist as a single element to the output list:
Tcl_ListObjAppendElement(interp, pOutList, pSubList);
EndLoop
Tcl_SetObjResult(interp, pOutList);
return TCL_OK;

Works like a charm, I get { {time1}{data1} {time2}{data2}...

Any C-programmer not terribly familiar with the Tcl API should immediately be concerned about the repeated Tcl_NewListObj(). Who cleans up ?

I made mistaken attempts to decrement the ref counter on pSubList at the end of the loop - resulting in various seg faults.
Having gained more understanding, perhaps some one can judge the following statements:

1. An AppendElement API call doesn't extend the size of the pOutList - it merely make a reference to the pSubList in pOutList. For that reason, the AppendElement call increments the ref counter on pSubList - it is now 'shared' and needs to stay alive.

2. The AppendElement API does *not* increment pOutList ref counter because that list is not shared anywhere. In fact the call will fail it is ever sees pOutList with a non-zero reference counter

3. The Tcl_SetObjResult(interp, pOutList); increments the Ref counter of pOutlist because the interpreter needs these data and it should not be cleaned up.

Now for the final statement. Lets say I call my C function in a loop:

While { 1 } {
set MyData [GetMyData ]
}

4. The Tcl interpreters will recursively Free the memory for ALL the lists objects created in a previous call to GetMyData upon executing the next one when $MyData is over-written. Right ? Otherwise we have a memory leak.

Let me know if (1)..(4) are correct. The bottom line is that I dont really need to worry about the ref counts of "temporary" lists (they aren't temporary) or what happens with my pOutList.

Much appreciated

Gertjan

Re: Understanding Tcl memory management of list created in C

<tj6qgg$1omqb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9877&group=comp.lang.tcl#9877

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: Understanding Tcl memory management of list created in C
Date: Mon, 24 Oct 2022 19:53:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <tj6qgg$1omqb$1@dont-email.me>
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
Injection-Date: Mon, 24 Oct 2022 19:53:53 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="7bf085fe0e1876852b222334c569e7f1";
logging-data="1858379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BPELcQuoFw3zFFcaU06zJ"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:+d+n+qUkHDHVcLen6YgGocA/8y4=
 by: Rich - Mon, 24 Oct 2022 19:53 UTC

Gertjan <ghofman@gmail.com> wrote:
> I could replicate the actual code but I think the pseudo version will
> do. Its typical I think.
>
> INT32 GetMyData (ClientData clientdata, Tcl_Interp *interp, INT32 argc, const CHAR *argv[])
>
> Loop over N data elements:
> Tcl_Obj *pSubList = Tcl_NewListObj(0,NULL);
>
> Now put Time and a Float into pSubList using two calls to
> TclListObjAppendElement(interp, pSubList,....);
>
> //copy the sublist as a single element to the output list:
> Tcl_ListObjAppendElement(interp, pOutList, pSubList);
> EndLoop
> Tcl_SetObjResult(interp, pOutList);
> return TCL_OK;
>
> Works like a charm, I get { {time1}{data1} {time2}{data2}...
>
> Any C-programmer not terribly familiar with the Tcl API should
> immediately be concerned about the repeated Tcl_NewListObj(). Who
> cleans up ?

Provided the extension writer does not do something funky with the ref
counter, the Tcl runtime cleans up when the last reference to the list
disappears.

> Having gained more understanding, perhaps some one can judge the
> following statements:
>
> 1. An AppendElement API call doesn't extend the size of the pOutList
> - it merely make a reference to the pSubList in pOutList. For that
> reason, the AppendElement call increments the ref counter on
> pSubList - it is now 'shared' and needs to stay alive.

Well, it does extend the size of pOutList - by one more element.

But yes, the sub-list will have it's refcount incremented as part of
the 'append' process.

> 2. The AppendElement API does *not* increment pOutList ref counter
> because that list is not shared anywhere. In fact the call will fail
> it is ever sees pOutList with a non-zero reference counter

It should not do so, because it is not creating a new reference to the
outer list container, so no reason to increment the ref counter of the
outer list.

> 3. The Tcl_SetObjResult(interp, pOutList); increments the Ref
> counter of pOutlist because the interpreter needs these data and it
> should not be cleaned up.

Yes, and at the same time, the Tcl runtime takes over 'ownership' and
tracking to determine when to free() the allocated memory.

> Now for the final statement. Lets say I call my C function in a
> loop:
>
> While { 1 } {
> set MyData [GetMyData ]
> }
>
> 4. The Tcl interpreters will recursively Free the memory for ALL the
> lists objects created in a previous call to GetMyData upon executing
> the next one when $MyData is over-written. Right ? Otherwise we
> have a memory leak.

Yes, each time MyData is overwritten, the old data in MyData will first
be freed.

> Let me know if (1)..(4) are correct. The bottom line is that I dont
> really need to worry about the ref counts of "temporary" lists (they
> aren't temporary) or what happens with my pOutList.

From your psudeo code, it looks like you likely don't need to do
anything with the ref counters for things to work out properly and for
Tcl to take over the lifetime management of the resulting list.

Re: Understanding Tcl memory management of list created in C

<HdydncmOG-FdaMv-nZ2dnZfqnPadnZ2d@giganews.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9879&group=comp.lang.tcl#9879

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!69.80.99.23.MISMATCH!Xl.tags.giganews.com!local-2.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Mon, 24 Oct 2022 20:29:52 +0000
MIME-Version: 1.0
From: hel...@deepsoft.com (Robert Heller)
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.15)
Subject: Re: Understanding Tcl memory management of list created in C
In-Reply-To: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
Newsgroups: comp.lang.tcl
Content-Type: text/plain; charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <HdydncmOG-FdaMv-nZ2dnZfqnPadnZ2d@giganews.com>
Date: Mon, 24 Oct 2022 20:29:52 +0000
Lines: 98
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-DBaOEZK5tnfiHdAw1Ku8jXgMMhR1rgnd0xkrI2OOea7xuP71cbNOFgKxtDpoerbukkKHrpPvPJZUdb5!LnazHOWaTlnEHJfY2P+VtjsbqVhnRP1SJ/yBDozMMCjPRalEMnyQqIGI9ugr86HA2fkaWGNVZ3YM!nhE=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Received-Bytes: 4824
 by: Robert Heller - Mon, 24 Oct 2022 20:29 UTC

At Mon, 24 Oct 2022 12:34:50 -0700 (PDT) Gertjan <ghofman@gmail.com> wrote:

>
> Hello,
>
> I spent a painful weekend trying to make more sensible Tcl list from data we generate in a C extension and to understand whether or not I am creating a memory leak. The return to the user is a List of List - pairs of time and ADC data in fact.
>
> I could replicate the actual code but I think the pseudo version will do. Its typical I think.
>
> INT32 GetMyData (ClientData clientdata, Tcl_Interp *interp, INT32 argc, const CHAR *argv[])
>
> Loop over N data elements:
> Tcl_Obj *pSubList = Tcl_NewListObj(0,NULL);
>
> Now put Time and a Float into pSubList using two calls to
> TclListObjAppendElement(interp, pSubList,....);
>
> //copy the sublist as a single element to the output list:
> Tcl_ListObjAppendElement(interp, pOutList, pSubList);
> EndLoop
> Tcl_SetObjResult(interp, pOutList);
> return TCL_OK;
>
> Works like a charm, I get { {time1}{data1} {time2}{data2}...
>
> Any C-programmer not terribly familiar with the Tcl API should immediately be concerned about the repeated Tcl_NewListObj(). Who cleans up ?
>
> I made mistaken attempts to decrement the ref counter on pSubList at the end of the loop - resulting in various seg faults.
> Having gained more understanding, perhaps some one can judge the following statements:
>
> 1. An AppendElement API call doesn't extend the size of the pOutList - it
> merely make a reference to the pSubList in pOutList. For that reason, the
> AppendElement call increments the ref counter on pSubList - it is now
> 'shared' and needs to stay alive.

Yes.

>
> 2. The AppendElement API does *not* increment pOutList ref counter because
> that list is not shared anywhere. In fact the call will fail it is ever sees
> pOutList with a non-zero reference counter

Yes.

>
> 3. The Tcl_SetObjResult(interp, pOutList); increments the Ref counter of
> pOutlist because the interpreter needs these data and it should not be
> cleaned up.

Yes.

>
> Now for the final statement. Lets say I call my C function in a loop:
>
> While { 1 } {
> set MyData [GetMyData ]
> }
>
> 4. The Tcl interpreters will recursively Free the memory for ALL the lists
> objects created in a previous call to GetMyData upon executing the next one
> when $MyData is over-written. Right ? Otherwise we have a memory leak.

Yes.

>
> Let me know if (1)..(4) are correct. The bottom line is that I dont really
> need to worry about the ref counts of "temporary" lists (they aren't
> temporary) or what happens with my pOutList.
>
> Much appreciated
>
> Gertjan

I believe you are correct.

Note: if you have C/C++ code that calls Tcl_Alloc for "internal" use, that
code needs to call Tcl_Free (eventually). Tcl_NewObj() (which is called by all
of the Tcl_New<mumble> functions) will take of the ref-count and the various
functions that set, append, etc. TclObjs to variables and such will also
update ref-counts as needed.

>
>
>
>
>
>
>
>
>
>

--
Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
heller@deepsoft.com -- Webhosting Services

Re: Understanding Tcl memory management of list created in C

<48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9880&group=comp.lang.tcl#9880

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:5cc5:b0:4b3:ec9e:79d8 with SMTP id lk5-20020a0562145cc500b004b3ec9e79d8mr28492646qvb.61.1666643972903;
Mon, 24 Oct 2022 13:39:32 -0700 (PDT)
X-Received: by 2002:ac8:5804:0:b0:39c:d63c:95b7 with SMTP id
g4-20020ac85804000000b0039cd63c95b7mr28363403qtg.216.1666643972736; Mon, 24
Oct 2022 13:39:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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, 24 Oct 2022 13:39:32 -0700 (PDT)
In-Reply-To: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.226.117; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.226.117
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com>
Subject: Re: Understanding Tcl memory management of list created in C
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Mon, 24 Oct 2022 20:39:32 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4195
 by: heinrichmartin - Mon, 24 Oct 2022 20:39 UTC

On Monday, October 24, 2022 at 9:34:52 PM UTC+2, Gertjan wrote:
> Hello,
>
> I spent a painful weekend trying to make more sensible Tcl list from data we generate in a C extension and to understand whether or not I am creating a memory leak. The return to the user is a List of List - pairs of time and ADC data in fact.
>
> I could replicate the actual code but I think the pseudo version will do. Its typical I think.
>
> INT32 GetMyData (ClientData clientdata, Tcl_Interp *interp, INT32 argc, const CHAR *argv[])
>
> Loop over N data elements:
> Tcl_Obj *pSubList = Tcl_NewListObj(0,NULL);

"The new list value returned by Tcl_NewListObj has reference count zero."; it will be incremented only in Tcl_ListObjAppendElement.
This also means, you must free it explicitly if you return prematurely.

About the same idea applies to the inner elements and the outer list.

Side-note: you could initialize the size with two, i.e. (2, NULL). "If objv is NULL, the resulting list contains 0 elements, with reserved space in an internal representation for objc more elements (to avoid its reallocation later)."

> //copy the sublist as a single element to the output list:

You have mentioned shared objects (copy on edit), i.e. "copy" is not exactly correct here.

> Any C-programmer not terribly familiar with the Tcl API should immediately be concerned about the repeated Tcl_NewListObj(). Who cleans up ?

Tcl, when the ref count drops to zero.

> 1. An AppendElement API call doesn't extend the size of the pOutList - it merely make a reference to the pSubList in pOutList. For that reason, the AppendElement call increments the ref counter on pSubList - it is now 'shared' and needs to stay alive.

It extends the size (by the definition of its semantics), but it does not create a string rep for the extended list. The consequence is correct anyway.

> 2. The AppendElement API does *not* increment pOutList ref counter because that list is not shared anywhere. In fact the call will fail it is ever sees pOutList with a non-zero reference counter

Yes, it does not touch the ref count, but I assume (don't know exactly) it is the caller's responsibility to not call it on shared lists (i.e. I assume no error on C level).

> 3. The Tcl_SetObjResult(interp, pOutList); increments the Ref counter of pOutlist because the interpreter needs these data and it should not be cleaned up.

Yes, increment from 0 to 1 in this case.

> Now for the final statement. Lets say I call my C function in a loop:
>
> While { 1 } {
> set MyData [GetMyData ]
> }
>
> 4. The Tcl interpreters will recursively Free the memory for ALL the lists objects created in a previous call to GetMyData upon executing the next one when $MyData is over-written. Right ? Otherwise we have a memory leak.

Not just _list_ objects. And replace free with decrement the ref count, i.e. you are not leaking unless the inner elements are leaking (in the part that is not part of your pseudo code).

Re: Understanding Tcl memory management of list created in C

<e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9881&group=comp.lang.tcl#9881

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:f2b:b0:4b1:7b01:6de2 with SMTP id iw11-20020a0562140f2b00b004b17b016de2mr28777790qvb.122.1666646427279;
Mon, 24 Oct 2022 14:20:27 -0700 (PDT)
X-Received: by 2002:a05:6214:27ea:b0:4b9:e0f5:22b0 with SMTP id
jt10-20020a05621427ea00b004b9e0f522b0mr18651723qvb.26.1666646427078; Mon, 24
Oct 2022 14:20:27 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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, 24 Oct 2022 14:20:26 -0700 (PDT)
In-Reply-To: <48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=146.112.65.212; posting-account=2h3mKAoAAAC6cHMkjCEBGx_FLAoEMKyZ
NNTP-Posting-Host: 146.112.65.212
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com> <48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
Subject: Re: Understanding Tcl memory management of list created in C
From: ghof...@gmail.com (Gertjan)
Injection-Date: Mon, 24 Oct 2022 21:20:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5718
 by: Gertjan - Mon, 24 Oct 2022 21:20 UTC

On Monday, October 24, 2022 at 1:39:35 p.m. UTC-7, heinrichmartin wrote:
> On Monday, October 24, 2022 at 9:34:52 PM UTC+2, Gertjan wrote:
> > Hello,
> >
> > I spent a painful weekend trying to make more sensible Tcl list from data we generate in a C extension and to understand whether or not I am creating a memory leak. The return to the user is a List of List - pairs of time and ADC data in fact.
> >
> > I could replicate the actual code but I think the pseudo version will do. Its typical I think.
> >
> > INT32 GetMyData (ClientData clientdata, Tcl_Interp *interp, INT32 argc, const CHAR *argv[])
> >
> > Loop over N data elements:
> > Tcl_Obj *pSubList = Tcl_NewListObj(0,NULL);
> "The new list value returned by Tcl_NewListObj has reference count zero."; it will be incremented only in Tcl_ListObjAppendElement.
> This also means, you must free it explicitly if you return prematurely.
>
> About the same idea applies to the inner elements and the outer list.
>
> Side-note: you could initialize the size with two, i.e. (2, NULL). "If objv is NULL, the resulting list contains 0 elements, with reserved space in an internal representation for objc more elements (to avoid its reallocation later)."
> > //copy the sublist as a single element to the output list:
> You have mentioned shared objects (copy on edit), i.e. "copy" is not exactly correct here.
> > Any C-programmer not terribly familiar with the Tcl API should immediately be concerned about the repeated Tcl_NewListObj(). Who cleans up ?
> Tcl, when the ref count drops to zero.
> > 1. An AppendElement API call doesn't extend the size of the pOutList - it merely make a reference to the pSubList in pOutList. For that reason, the AppendElement call increments the ref counter on pSubList - it is now 'shared' and needs to stay alive.
> It extends the size (by the definition of its semantics), but it does not create a string rep for the extended list. The consequence is correct anyway.
> > 2. The AppendElement API does *not* increment pOutList ref counter because that list is not shared anywhere. In fact the call will fail it is ever sees pOutList with a non-zero reference counter
> Yes, it does not touch the ref count, but I assume (don't know exactly) it is the caller's responsibility to not call it on shared lists (i.e. I assume no error on C level).
> > 3. The Tcl_SetObjResult(interp, pOutList); increments the Ref counter of pOutlist because the interpreter needs these data and it should not be cleaned up.
> Yes, increment from 0 to 1 in this case.
> > Now for the final statement. Lets say I call my C function in a loop:
> >
> > While { 1 } {
> > set MyData [GetMyData ]
> > }
> >
> > 4. The Tcl interpreters will recursively Free the memory for ALL the lists objects created in a previous call to GetMyData upon executing the next one when $MyData is over-written. Right ? Otherwise we have a memory leak.
> Not just _list_ objects. And replace free with decrement the ref count, i..e. you are not leaking unless the inner elements are leaking (in the part that is not part of your pseudo code).

Rich,Robert, Martin,

Slight inconsistencies in my language aside, I think I am on the right track and thank you all for confirming. I have a feeling a bit of basic knowledge like this should find it self at the top of the API documentation. The Wiki has some pages on dec/inc ref counters but it doesn't clarify the fundamentals: objects become shared, appends do not "expand/copy" and this is why if you do any operations like 'appending' list A to list B, then to modify list A lafter you need to duplicate it first.
i There is a further consequence here. If in a script you have a very large list A and append/concat to list B, there is almost no CPU overhead. But then if you modify list A later, there must be significant overhead as list A now must be duplicated. i.e.

5. In the following code:

set A { some very large list}
lappend B {*}$A
lappend A {"hello world"}

there is almost no CPU overhead for the first lappend, which adds a massive list A to B. But a single item addition on the 2nd lappend is quite costly. Correct ?

Again, I appreciate the fast response I got here.

Cheers

G

Re: Understanding Tcl memory management of list created in C

<4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9882&group=comp.lang.tcl#9882

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:ac8:7dc4:0:b0:39c:f95f:57fe with SMTP id c4-20020ac87dc4000000b0039cf95f57femr26919275qte.612.1666651054134;
Mon, 24 Oct 2022 15:37:34 -0700 (PDT)
X-Received: by 2002:a05:620a:3720:b0:6dd:beba:b3a1 with SMTP id
de32-20020a05620a372000b006ddbebab3a1mr23848993qkb.138.1666651053992; Mon, 24
Oct 2022 15:37:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.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: Mon, 24 Oct 2022 15:37:33 -0700 (PDT)
In-Reply-To: <e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.115.226.117; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 84.115.226.117
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com> <e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com>
Subject: Re: Understanding Tcl memory management of list created in C
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Mon, 24 Oct 2022 22:37:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: heinrichmartin - Mon, 24 Oct 2022 22:37 UTC

On Monday, October 24, 2022 at 11:20:29 PM UTC+2, Gertjan wrote:
> Slight inconsistencies in my language aside, I think I am on the right track and thank you all for confirming. I have a feeling a bit of basic knowledge like this should find it self at the top of the API documentation. The Wiki has some pages on dec/inc ref counters but it doesn't clarify the fundamentals: objects become shared, appends do not "expand/copy" and this is why if you do any operations like 'appending' list A to list B, then to modify list A lafter you need to duplicate it first.
> i
> There is a further consequence here. If in a script you have a very large list A and append/concat to list B, there is almost no CPU overhead. But then if you modify list A later, there must be significant overhead as list A now must be duplicated. i.e.

Indeed, knowing the internals can speed up scripts (or the other way round, you might encounter unexpectedly slow sections if you were not aware of some internals). Shimmering (i.e. switching between representations) is one example - not the one that you are after, but a simple one:
Creating a long list by appending items in a (tight) loop is fast in Tcl until you log the list in every iteration. File/console operation is the expected factor, but actually creating the string representation is an unexpected one (in a language that emphasizes "everything is a string"). On the other hand, this makes Tcl great imho - be flexible while coding, be fast if possible.

> set A { some very large list}
> lappend B {*}$A

This requires at least:
- realloc in B
- memcopy pointers from A to end of B
- ref incr on all elements of A

> lappend A {"hello world"}

This might not even require a realloc, because Tcl allocates internal list presentation progressively.
It duplicates the object in A only if it is shared, which is not the case here.

Side-note: [lindex $A end] will be a string including the quotation marks; this might or might not be expected.

> there is almost no CPU overhead for the first lappend, which adds a massive list A to B. But a single item addition on the 2nd lappend is quite costly. Correct ?

I'd say the first operation is more expensive than the second one.

Btw, ::tcl::unsupported::representation is quite nice to learn about internals, but an interactive session might thwart your efforts in two ways:
1. it creates string representations to display results
2. it might hold copies of parameters in the command history

Re: Understanding Tcl memory management of list created in C

<ygay1t4qo84.fsf@akutech.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9888&group=comp.lang.tcl#9888

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Understanding Tcl memory management of list created in C
Date: Tue, 25 Oct 2022 10:52:43 +0200
Lines: 11
Message-ID: <ygay1t4qo84.fsf@akutech.de>
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<HdydncmOG-FdaMv-nZ2dnZfqnPadnZ2d@giganews.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Gl+c59OwDVATzG7tBhJt6QpEr+8u9kwkYKIzmdH23oOXry3Uo=
Cancel-Lock: sha1:Duhz80DQ41ktUrMbBdZvJmrPWzE= sha1:Zs0nq6OMbXlVh7hzunnbnF8sErw=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Tue, 25 Oct 2022 08:52 UTC

* Robert Heller <heller@deepsoft.com>
| > 2. The AppendElement API does *not* increment pOutList ref counter because
| > that list is not shared anywhere. In fact the call will fail it is ever sees
| > pOutList with a non-zero reference counter
>
| Yes.

Nitpick: [...] In fact the call will fail it is ever sees pOutList with
a reference counter *greater than 1* (i.e. a shared list obj).

R'

Re: Understanding Tcl memory management of list created in C

<tj8cgo$1v0qk$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9891&group=comp.lang.tcl#9891

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Understanding Tcl memory management of list created in C
Date: Tue, 25 Oct 2022 12:07:16 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <tj8cgo$1v0qk$2@dont-email.me>
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<HdydncmOG-FdaMv-nZ2dnZfqnPadnZ2d@giganews.com> <ygay1t4qo84.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 25 Oct 2022 10:07:20 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="484796883f9d271dac05ff063d89fde7";
logging-data="2065236"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194N1P+jqn9q/gKEht3KD/E"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.0
Cancel-Lock: sha1:CCVpaz9SaSgu/bwMtGhb8Gyihr4=
In-Reply-To: <ygay1t4qo84.fsf@akutech.de>
Content-Language: en-GB
 by: Harald Oehlmann - Tue, 25 Oct 2022 10:07 UTC

Am 25.10.2022 um 10:52 schrieb Ralf Fassel:
> * Robert Heller <heller@deepsoft.com>
> | > 2. The AppendElement API does *not* increment pOutList ref counter because
> | > that list is not shared anywhere. In fact the call will fail it is ever sees
> | > pOutList with a non-zero reference counter
>>
> | Yes.
>
> Nitpick: [...] In fact the call will fail it is ever sees pOutList with
> a reference counter *greater than 1* (i.e. a shared list obj).
>
> R'

Dear Folks,

I appreciate this thread, as it is a common issue.
I personally got the basics from the outdated book by Jeff Hobbs.

A good wiki page is:

https://wiki.tcl-lang.org/page/Tcl%5FObj+refCount+HOWTO

As a fist documentation step, additionaly information may be added there.

Thank you all,
Harald

Re: Understanding Tcl memory management of list created in C

<583801b6-a816-42f2-822e-74e6d38e7bcdn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9905&group=comp.lang.tcl#9905

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:20e2:b0:4bb:7aa5:bf0a with SMTP id 2-20020a05621420e200b004bb7aa5bf0amr8550154qvk.112.1666735408999;
Tue, 25 Oct 2022 15:03:28 -0700 (PDT)
X-Received: by 2002:a05:6214:1c0c:b0:4b1:d2fe:7ad4 with SMTP id
u12-20020a0562141c0c00b004b1d2fe7ad4mr34533418qvc.128.1666735408842; Tue, 25
Oct 2022 15:03:28 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Tue, 25 Oct 2022 15:03:28 -0700 (PDT)
In-Reply-To: <4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=155.190.0.10; posting-account=2h3mKAoAAAC6cHMkjCEBGx_FLAoEMKyZ
NNTP-Posting-Host: 155.190.0.10
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com> <e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
<4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <583801b6-a816-42f2-822e-74e6d38e7bcdn@googlegroups.com>
Subject: Re: Understanding Tcl memory management of list created in C
From: ghof...@gmail.com (Gertjan)
Injection-Date: Tue, 25 Oct 2022 22:03:28 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4906
 by: Gertjan - Tue, 25 Oct 2022 22:03 UTC

On Monday, October 24, 2022 at 3:37:36 p.m. UTC-7, heinrichmartin wrote:
> On Monday, October 24, 2022 at 11:20:29 PM UTC+2, Gertjan wrote:
> > Slight inconsistencies in my language aside, I think I am on the right track and thank you all for confirming. I have a feeling a bit of basic knowledge like this should find it self at the top of the API documentation. The Wiki has some pages on dec/inc ref counters but it doesn't clarify the fundamentals: objects become shared, appends do not "expand/copy" and this is why if you do any operations like 'appending' list A to list B, then to modify list A lafter you need to duplicate it first.
> > i
> > There is a further consequence here. If in a script you have a very large list A and append/concat to list B, there is almost no CPU overhead. But then if you modify list A later, there must be significant overhead as list A now must be duplicated. i.e.
> Indeed, knowing the internals can speed up scripts (or the other way round, you might encounter unexpectedly slow sections if you were not aware of some internals). Shimmering (i.e. switching between representations) is one example - not the one that you are after, but a simple one:
> Creating a long list by appending items in a (tight) loop is fast in Tcl until you log the list in every iteration. File/console operation is the expected factor, but actually creating the string representation is an unexpected one (in a language that emphasizes "everything is a string"). On the other hand, this makes Tcl great imho - be flexible while coding, be fast if possible.
> > set A { some very large list}
> > lappend B {*}$A
> This requires at least:
> - realloc in B
> - memcopy pointers from A to end of B
> - ref incr on all elements of A
>
> > lappend A {"hello world"}
>
> This might not even require a realloc, because Tcl allocates internal list presentation progressively.
> It duplicates the object in A only if it is shared, which is not the case here.
>
> Side-note: [lindex $A end] will be a string including the quotation marks; this might or might not be expected.
> > there is almost no CPU overhead for the first lappend, which adds a massive list A to B. But a single item addition on the 2nd lappend is quite costly. Correct ?
> I'd say the first operation is more expensive than the second one.
>
> Btw, ::tcl::unsupported::representation is quite nice to learn about internals, but an interactive session might thwart your efforts in two ways:
> 1. it creates string representations to display results
> 2. it might hold copies of parameters in the command history

Martin,

Since this is a conceptual learning exercise I need to ask you to clarify this response of your or it ruins what I think I learned :)
1. You said that in my example:

set A { some very large list}
lappend B {*}$A
lappend A {"hello world"}

That the last line "does not even require a realloc....it duplicates only if A is shared". But A IS shared - it becomes shared once lappend B{*}$A is executed. Right ?

2. Perhaps related: "I'd say the first operation is more expensive than the second one.". Again - no - the 1st lappend is cheap because B is merely linked to A. But the 2nd is very expensive because that is when A is necessarily duplicated and may not be modified since it's Ref count >= 1.

Appreciate your thoughts.

Thanks - G

Re: Understanding Tcl memory management of list created in C

<yga35bahft9.fsf@akutech.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9912&group=comp.lang.tcl#9912

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Understanding Tcl memory management of list created in C
Date: Wed, 26 Oct 2022 15:31:30 +0200
Lines: 45
Message-ID: <yga35bahft9.fsf@akutech.de>
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com>
<e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
<4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com>
<583801b6-a816-42f2-822e-74e6d38e7bcdn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net NpaFP/QAJKjtCqjvJXStyAb2M0X1TxenrtmzWGjVRiAt3hCxk=
Cancel-Lock: sha1:pqaQsWrZVl3IYrNsF9VqqljCLXI= sha1:wHgw09FyVnLPB+X5LFQxkozHxKM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Wed, 26 Oct 2022 13:31 UTC

* Gertjan <ghofman@gmail.com>
| 1. You said that in my example:
>
| set A { some very large list}
| lappend B {*}$A
| lappend A {"hello world"}
>
| That the last line "does not even require a realloc....it duplicates
| only if A is shared". But A IS shared - it becomes shared once
| lappend B{*}$A is executed. Right ?

Wrong, since

lappend B {*}$A

does *not* lappend A, it lappends every element of A.
The refcount of every element of A is incr'd after that, but A's refcount itself is not:

% set A [list some very large list]
some very large list
% ::tcl::unsupported::representation $A
value is a list with a refcount of 3, object pointer at 0x1afeeb0, internal representation 0x1b4e360:(nil), string representation "some very lar..."

% lappend B {*}$A
some very large list
% ::tcl::unsupported::representation $A
value is a list with a refcount of 3, object pointer at 0x1b030b0, internal representation 0x1b2b3a0:(nil), string representation "some very lar..."

Note how the refcount did not change (don't ask me why it is *3* and not
1 or 2).

Now
lappend B $A
is a different beast, here indeed A is shared after that.

% lappend B $A
{some very large list}
% ::tcl::unsupported::representation $A
value is a list with a refcount of 4, object pointer at 0x1b030b0, internal representation 0x1b2b3a0:(nil), string representation "some very lar..."

Note how the refcount *did* change.

HTH
R'

Re: Understanding Tcl memory management of list created in C

<tjbeod$2do02$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9913&group=comp.lang.tcl#9913

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Understanding Tcl memory management of list created in C
Date: Wed, 26 Oct 2022 16:03:56 +0200
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <tjbeod$2do02$1@dont-email.me>
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com>
<e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
<4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com>
<583801b6-a816-42f2-822e-74e6d38e7bcdn@googlegroups.com>
<yga35bahft9.fsf@akutech.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 26 Oct 2022 14:03:57 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="b68062bdfcb5f8f3f0033f52408a5d34";
logging-data="2547714"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/pyl3i9VrwVhFWQH5bWAq"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.4.0
Cancel-Lock: sha1:vVVyIDZdpxjJ2yNOo79ZU11PWU0=
In-Reply-To: <yga35bahft9.fsf@akutech.de>
Content-Language: en-GB
 by: Harald Oehlmann - Wed, 26 Oct 2022 14:03 UTC

Am 26.10.2022 um 15:31 schrieb Ralf Fassel:> Note how the refcount did
not change (don't ask me why it is *3* and not
> 1 or 2).

That is due to the history package, active in interactive mode.
The history package makes copies of each command, which increments the
ref-count of all objects.

% set A { some very large list};
some very large list
% lappend B {*}$A
some very large list
% ::tcl::unsupported::representation $A
value is a list with a refcount of 4, object pointer at 008767C0,
internal representation 03EB5D78:00000000, string representation " some
very la..."
% history clear ; ::tcl::unsupported::representation $A
value is a list with a refcount of 2, object pointer at 008767C0,
internal representation 03EB5D78:00000000, string representation " some
very la..."

Another surprising way of refcount increment is, if an object is the
result of a command and thus copied to the interpreter result field.

Harald

Re: Understanding Tcl memory management of list created in C

<0f3d14ce-3b57-4416-8ea1-3e86e53a1f60n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9915&group=comp.lang.tcl#9915

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a37:48c:0:b0:6f8:70d5:9a41 with SMTP id 134-20020a37048c000000b006f870d59a41mr6210090qke.676.1666818952671;
Wed, 26 Oct 2022 14:15:52 -0700 (PDT)
X-Received: by 2002:ac8:594d:0:b0:39c:ebcb:913b with SMTP id
13-20020ac8594d000000b0039cebcb913bmr38282099qtz.501.1666818952500; Wed, 26
Oct 2022 14:15:52 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.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: Wed, 26 Oct 2022 14:15:52 -0700 (PDT)
In-Reply-To: <tjbeod$2do02$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=146.112.65.212; posting-account=2h3mKAoAAAC6cHMkjCEBGx_FLAoEMKyZ
NNTP-Posting-Host: 146.112.65.212
References: <fc2400d8-6b59-43bb-b2be-1b7cfb4d7683n@googlegroups.com>
<48043a42-6169-419a-9547-b6811e5edaafn@googlegroups.com> <e1a7db0f-76af-4738-afb2-b9821f779a65n@googlegroups.com>
<4b18558a-e1f1-4a35-9e09-1d33cb7a8b7en@googlegroups.com> <583801b6-a816-42f2-822e-74e6d38e7bcdn@googlegroups.com>
<yga35bahft9.fsf@akutech.de> <tjbeod$2do02$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0f3d14ce-3b57-4416-8ea1-3e86e53a1f60n@googlegroups.com>
Subject: Re: Understanding Tcl memory management of list created in C
From: ghof...@gmail.com (Gertjan)
Injection-Date: Wed, 26 Oct 2022 21:15:52 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2994
 by: Gertjan - Wed, 26 Oct 2022 21:15 UTC

On Wednesday, October 26, 2022 at 7:04:06 a.m. UTC-7, Harald Oehlmann wrote:
> Am 26.10.2022 um 15:31 schrieb Ralf Fassel:> Note how the refcount did
> not change (don't ask me why it is *3* and not
> > 1 or 2).
> That is due to the history package, active in interactive mode.
> The history package makes copies of each command, which increments the
> ref-count of all objects.
>
> % set A { some very large list};
> some very large list
> % lappend B {*}$A
> some very large list
> % ::tcl::unsupported::representation $A
> value is a list with a refcount of 4, object pointer at 008767C0,
> internal representation 03EB5D78:00000000, string representation " some
> very la..."
> % history clear ; ::tcl::unsupported::representation $A
> value is a list with a refcount of 2, object pointer at 008767C0,
> internal representation 03EB5D78:00000000, string representation " some
> very la..."
>
> Another surprising way of refcount increment is, if an object is the
> result of a command and thus copied to the interpreter result field.
>
> Harald

Harald, Ralf - Thanks. My example was sloppy, I should have used lappend B $A. Well, perhaps ignorance, not sloppy: I did not consider the ref count of individual list objects versus the list itself. And indeed, in my C function, where I first run into this, I am appending $A as a single item to B, so observe the refcount increment on A.

Again, much appreciated.

Gertjan

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor