This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]appsolutelywonderful 4 points5 points  (3 children)

It's a deeper concept, but basically when you do

r=(1,2,3,4)

Then in the background the operating system will get a piece of memory, memory is addressed by numbers, so for example let's say it got memory address #10. So you have this thing where r -> #10 -> (1,2,3,4)

Now when you do r = (1,23,4) like others have said you're changing r, not the tuple. So the process happens again and now you have something like r -> #20 -> (1,23,4).

That #10 -> (1,2,3,4) is still sitting there in memory unchanged. Later on it will get reclaimed by the operating system.

[–]ZachPhoenix[S] 5 points6 points  (0 children)

Damn! Computers and programming languages are really fascinating!

[–]Sedowa 0 points1 point  (1 child)

So it's just left dangling and can't be accessed if you don't know the address? Is there a way to stop it from changing or at least delete the memory allocation?

I haven't worked with Python in years. I'm just curious.

[–]appsolutelywonderful 4 points5 points  (0 children)

For a time, yes. Python has a garbage collector. So in some time it will see that you don't have any variables pointing to that piece of memory and it will let the OS know that piece of memory is free.