can someone explains to me about the object lifecycle in a simpler way?? I couldn't understand it at all.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

can someone explains to me about the object lifecycle in a simpler way?? I couldn't understand it at all..

please someone help..

5th Jul 2016, 7:06 AM
yogaocean
yogaocean - avatar
4 Answers
+ 10
let's start simple say you assign 5 to a variable a 'a =5' what you did is you create the object 5 of type integer an bind it with name a. what's happen is that Python has what we call a reference counting and that counts how many references point to an object. say you decided to create an other variable b, b = a. now b is bond to 5 same as a is bound to the same five. the reference counter now counts 2 reference for the object 5. now we want to get rid of the variable a. 'del a'. the reference count for 5 decrease by 1. if we do the same for b then the object 5 will be garbage collected (deleted from the memory). to be more general, an object is kept in memory as long as he has something bonded to it or using it. if no one is referring to it (bounded to it) Python will delete it. and that's why we love python. he takes care of us and help us to sleep well.
5th Jul 2016, 4:47 PM
zak
+ 1
you are welcome @yogaocean 😊
6th Jul 2016, 11:40 PM
zak
0
thank you very much @zak.. your explanation really easy to understand.. i will keep that in mind.. especially on the last sentences.. :D
5th Jul 2016, 4:52 PM
yogaocean
yogaocean - avatar
0
Simple and clear explanation, thank @Zak!
23rd Dec 2016, 2:59 PM
María F.A.
María F.A. - avatar