Why do immutable variables need reference counting?
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Apr 13 16:33:16 UTC 2022
On Wed, Apr 13, 2022 at 08:39:17AM -0700, Ali Çehreli via Digitalmars-d-learn wrote:
> On 4/12/22 21:34, Salih Dincer wrote:
>
> > I tried the following and I didn't understand one thing: Why is
> > there no need to use dup when slicing?
[...]
Because of two things: (1) there is a GC, and (2) characters in a string
are immutable.
Without (1), you will end up with either a memory leak or a dangling
pointer; without (2), your slice may randomly mutate when you don't
expect it to.
T
--
May you live all the days of your life. -- Jonathan Swift
More information about the Digitalmars-d-learn
mailing list