←back to thread

498 points azhenley | 1 comments | | HN request time: 0.001s | source
Show context
sgarland ◴[] No.45770550[source]
Dumb question from a primarily Python programmer who mostly writes (sometimes lengthy) scripts: if you have a function doing multiple API calls - say, to different AWS endpoints with boto3 - would you be expected to have a different variable for each response? Or do you delete the variable after it’s handled, so the next one is “new?”
replies(3): >>45770602 #>>45770650 #>>45770806 #
TZubiri ◴[] No.45770602[source]
I think renaming an old variable is a common and sensible way to free a resource in python. If there are no valid names for a resource it will be garbage collected. Which is different in languages like C++ with manual memory management.

John Carmack is a C++ programmer apparently that still has a lot to learn in python.

replies(4): >>45770941 #>>45770988 #>>45773607 #>>45777177 #
1. maleldil ◴[] No.45773607[source]
Not "a resource", but memory specifically. If there's a proper resource (e.g. a file), you should ensure it's explicitly released instead of relying on the GC (using with/close/etc.) And if memory usage is really important, you should probably explicitly delete the variable.

Anything else is wishful thinking, trying to rely on the GC for deterministic behaviour.