+ 2

Is it better to delete variables at the end of functions?

I read that deleting them is just deleting the references.. is it true? does that differ according to the language or it is general?

2nd Jun 2018, 11:31 AM
Nahi Bul
Nahi Bul - avatar
7 odpowiedzi
+ 2
What language?
2nd Jun 2018, 12:18 PM
ifl
ifl - avatar
+ 2
It is important to free up memory in in C and C++ because there is no garbage collection. in other languages that have garbage collection, less so, as memory is eventually freed up when the variables are out of scope.
2nd Jun 2018, 12:33 PM
ifl
ifl - avatar
+ 1
I am not sure about what you read, :-) Good practice in that area is language specific... You may want to read about memory allocation and garbage collection, reference counting, and heap vs. stack, and the role of constructor/destructor (esp. in C++)
2nd Jun 2018, 12:39 PM
ifl
ifl - avatar
0
Whatever.. I mean is it a good practice? You ask about the language.. so it depends?
2nd Jun 2018, 12:22 PM
Nahi Bul
Nahi Bul - avatar
0
In python (I believe) there is reference counting and garbage collection. The variable dies when nothing "knows about it in the rest of the application.
2nd Jun 2018, 12:41 PM
ifl
ifl - avatar
0
thank you so much.. at least now I have key words to look for.. am grateful ;)
2nd Jun 2018, 12:41 PM
Nahi Bul
Nahi Bul - avatar
- 1
I am learning python now.. and thought that whenever I finish the function.. its local variables die. but in java I think it is not the same.. I am a little lost
2nd Jun 2018, 12:29 PM
Nahi Bul
Nahi Bul - avatar