I figured it. I was using std::maked_shared on the returned ChemicalReaction 
pointer, but the shared pointer was not performing as anticipated in the copy 
constructors. Eliminating the shared pointer conversion, adding an explicit 
delete to the destructor, and deep pointer copies to the copy constructors 
fixed the memory leak.

Sent from my iPhone

On Jul 3, 2023, at 1:36 PM, Jarod Younker <jarod_youn...@hotmail.com> wrote:


Posted the Valgrind HEAP Summary showing the memory allocation in the shared 
library … When the pointer goes out of scope, that memory must not be 
deallocated.  Bug?

==10036== HEAP SUMMARY:
==10036==     in use at exit: 2,324,704 bytes in 31,944 blocks
==10036==   total heap usage: 140,499 allocs, 108,555 frees, 8,952,289 bytes 
allocated
==10036==
==10036== 2,324,704 (15,232 direct, 2,309,472 indirect) bytes in 136 blocks are 
definitely lost in loss record 93 of 93
==10036==    at 0x4845013: operator new(unsigned long) (in 
/usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==10036==    by 0x4B0D550: 
RDKit::RxnSmartsToChemicalReaction(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >
const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> >, std::__cxx11::basic_string<char, std::char
_traits<char>, std::allocator<char> >, 
std::less<std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > >, std::allo
cator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const, std::__cxx11::basic_string<char, std::
char_traits<char>, std::allocator<char> > > > >*, bool, bool) (in 
/opt/rdkit-Release_2022_09_2/lib/libRDKitChemReactions.so.1.2022.09.1)
==10036==    by 0x11E943: 
kMC::Reaction::Reaction(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >, double, st
d::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) 
(Reaction.cpp:18)

Sent from my iPhone

On Jul 3, 2023, at 12:48 PM, Jarod Younker <jarod_youn...@hotmail.com> wrote:

The function RxnSmartsToChemicalReaction() returns a pointer to a 
ChemicalReaction object.

Is this pointer a std::unique_ptr?

How does one deallocate said pointer after it goes out of scope?

Valgrind identifies a definite memory loss in libRDKitChemReactions.so from a 
new(unsigned long)

Thanks,

J

Sent from my iPhone

_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Frdkit-discuss&data=05%7C01%7C%7C8d25b02bc4ab44cc1ad708db7beda725%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638240032871322956%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=8Dmfydb9VO9ApXMonLqqRQot3LUvpD4ijtWUmOrUPWw%3D&reserved=0
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to