mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-07 17:15:29 +00:00
Fix memory cleanup on unload
This commit is contained in:
parent
a36dd5d574
commit
5c6910ed9c
1 changed files with 5 additions and 1 deletions
|
|
@ -172,7 +172,11 @@ class CUDAExecutionProvider : public IExecutionProvider {
|
|||
|
||||
struct ContextCacheHolder {
|
||||
ContextCacheHolder() {
|
||||
RunOnUnload([this] { p.reset(); });
|
||||
// Keep a weak pointer to the object, if the weak pointer can be locked, then the shared pointer is still around, so we can reset it
|
||||
RunOnUnload([&, weak_p_ = std::weak_ptr<PerThreadContextMap>(p)] {
|
||||
if (auto lock = weak_p_.lock())
|
||||
p.reset();
|
||||
});
|
||||
}
|
||||
std::shared_ptr<PerThreadContextMap> p{std::make_shared<PerThreadContextMap>()};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue