weak_ptr is like shared_ptr but doesn't add to the count. When the last shared_ptr is destroyed it destroys the object even if there are still weak_ptrs. Any weak_ptrs pointing to that object become null. I won't dive into how that's actually implemented. Obviously it costs some CPU cycles to make that happen, so you don't see shared_ptr or weak_ptr a lot in code that's written with a performance mindset. Although you're still getting 90% of the performance benefit by writing C++ instead of JS even if it's "inefficient" C++.
I agree with GP's point and add, if this isn't something you need to do, then don't even think about it. C++ is like a toolbox with a bunch of tools. I don't study all the tools before building a table, I look up how to build a table, and then see if the tools are in my toolbox. Studying the triangle screwdriver would be a waste of time and only confuse me more, unless I'm trying to drive triangle screws. Only when I need to drive a triangle screw then I can look for the triangle screwdriver.
https://docs.python.org/3/library/weakref.html
Anyone that thinks Python is "simple", to come back to some of the suggestions on how it is easier than C++, they really should learn the language reference, standard library, and CPython FFI manuals.
Python is more "simple" in the sense that
- it is more forgiving with respect to badly written code,
- it has collected less historical baggage than C++.
Otherwise I agree.
Yeah, we all know how cleaning up Python has worked out, and unfortunately a few ecosystems failed to learn from it as well, e.g. Java 8 => 9, .NET Framework => Core.
Yes, Python may still blow up at runtime if you don't get it exactly right, but it'll blow up in very predictable ways: Off by one errors accessing arrays doesn't work some of the time, maybe, except on Tuesdays, instead you always get an IndexError. And some cases, like overflows/underflows, doesn't even blow up, instead you just get bigger/smaller numbers.
Type-hints also does a lot (but still not enough, IMO) to reduce the amount of blowing at runtime up that you might experience when working in Python. Though that obviously wont help with poorly written code, which is unlikely to have proper type hints
Exactly.