0
MASS N NUMBER OF OBJECT DELETION FROM A CLASS
If i want to delete n number of objects from my custom class than how will I do it Note : I don't know how many objects are created from that class and also deletion of all objects will be done in one line command
3 Answers
+ 2
from your profile, I can only see c++ codebits. Perhaps you can write a sample file to show the problem for us.
del in Python is not a simple thing because Python is a garbage collected language and there is a reference counting system going on under the hood...
i would probably instantiate the objects in a list instead of assigning them individually to variables, just to keep them in one place, then clear the list to get rid of them all in one step.
+ 1
Can you get a count of how many objects there are in the class?
Look at iteration functions/methods if you're not sure.
+ 1
or maybe use weakref, and use a static list to hold the actual references. then you can define a delete_all_instances method to delete all instances in one line of code. weakrefs provides an isolation from the object reference counter.
https://sololearn.com/compiler-playground/crT9AhPKI4Y1/?ref=app