Tutorial: How to set up Smart Pointers and TR1 C++ in the Android NDK
Optimus prime is a smart pointer. Memory leaks?! He'll straight up kick you in the throat! This isn't Go Bots son! What's the point If you have ever coded in C or C++ you know you've had a memory leak some time or another. Ownership semantics are best, but sometimes those are muddy and, most of the time, the benefit of automatically reclaimed pointers far outweighs any costs (they are not much in terms of resources). What are smart pointers? These are pointer containers/classes with reference counting and ownership semantics built in. The easiest to understand and use is shared_ptr , which when all references are gone delete's the object from memory, and as expected calls the objects destructor (if it exists). For example if you create a raw pointer in a function (and don't store a reference to it anywhere else) you would get a memory leak! void leak_function() { Sprite* sprite = new Sprite(); // Use sprite // After functio...