# Garbage collecting stale global variable value copies

**URL:** <https://swi-prolog.discourse.group/t/garbage-collecting-stale-global-variable-value-copies/3928>\
**Category:** Predicate\
**Created:** [May 7, 2021, 4:07pm UTC](https://swi-prolog.discourse.group/t/garbage-collecting-stale-global-variable-value-copies/3928 "2021-05-07T16:07:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 7, 2021, 4:07pm UTC](https://swi-prolog.discourse.group/t/garbage-collecting-stale-global-variable-value-copies/3928/1 "2021-05-07T16:07:56Z")

</div>

The doc for `nb_setval(+Name,+Value)` states that a copy of value is made and associated with `Name`. When a second call is made to overwrite the first copy of `Value`, is that (no longer referenced) copy garbage collected?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 7, 2021, 4:37pm UTC](https://swi-prolog.discourse.group/t/garbage-collecting-stale-global-variable-value-copies/3928/2 "2021-05-07T16:37:31Z")

</div>

Sure. Otherwise it wouldn’t be much use, no?

---

<div class="post-metadata">

**Author:** ![ridgeworks](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ridgeworks/32/886_2.png) [@ridgeworks](https://swi-prolog.discourse.group/u/ridgeworks)\
**Post date:** [May 7, 2021, 4:50pm UTC](https://swi-prolog.discourse.group/t/garbage-collecting-stale-global-variable-value-copies/3928/3 "2021-05-07T16:50:53Z")

</div>

True. I was unexpectedly running out of heap but I think I’ve traced that down to heavy use of `library(gensym)`; things working better now.
