To add to this: you are looking at the wonderful concept of an "undefined behavior" in C/C++. There is no guarantee that your example program will always show the same behaviour.
In more recent versions of C++, you have access to "smart pointers" like std::shared_ptr, which basically implement reference counting. Not sure if this would help here. Best regards, Nils Am 27.08.2020 um 21:42 schrieb dmaziuk via Rdkit-discuss: > On 8/27/2020 2:15 PM, Jason Biggs wrote: > >> What I'm trying to understand right now is the expected lifetime of an >> Atom >> pointer returned by a molecule, for instance by the getAtomWithIdx >> method. >> Based on the documentation, since this method doesn't say the user is >> responsible for deleting the returned pointer I know I'm not supposed to >> delete it. But when exactly does it get deleted? If I dereference it >> after >> deleting the molecule, what is it? > > The more general answer is: > > a) when the program terminates, all its resources are returned to the > OS. It was a common CGI technique to not bother and just let the it run > to the end. (It was also one of the "mobile Java" things with cellphone > vendors: they wanted garbage collection off.) > > b) Unlike "garbage-collected" languages c++ has guaranteed object > destruction. If there's any resources you want to explicitly relinquish, > the destructor is the place to do it. > > If your program is not an "up forever" server, you could just let it be: > it'll all get cleaned up on exit. > > HTH, > Dima > > > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss _______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss