I was trying some recursive code in which I create a string outside the first call of my recursive function, and send that string as an argument to said first call. This string gets passed around a ton of times inside a recursive algorithm.
Inside this function, the string is mutated using +=
. This function obviously gets called a lot as its recursive. I assumed each modification to the string wouldn't inadvertently affect the other function as +=
should create a new instance of the string, but it seems that sometimes it does mutate it and affects other calls of my function.
I did some digging around (picture above) and found that when doing +=
to a function sometimes it keeps its id
, though I don't know if this confirms my suspicion.
Anyone have any idea of what could be happening?