unitaryfund / qrack

Comprehensive, GPU accelerated framework for developing universal virtual quantum processors
https://qrack.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
177 stars 38 forks source link

Don't hold strong references to QInterfacePtr in maps #891

Closed WrathfulSpatula closed 3 years ago

WrathfulSpatula commented 3 years ago

It seems like PyQrack is holding onto simulator instance garbage after destructors are called, but this is likely in the shared library itself, and the obvious suspects are the maps by (shared_ptr) QInterfacePtr. I'm testing, right now, whether removing these strong references lets garbage be disposed. I would use a weak_ptr rather than a raw pointer, and I have to apologize for that, but weak_ptr doesn't seem have ordering operators that allow it to be used as the keys of std::map, at least in C++11. However, it'll be obvious fairly quickly whether this change lets us release garbage, and we don't access these maps' keys in iteration over key-value pairs, (only values).

This is subject to change, but it will probably be accepted as-is, if tests in progress remain stable.