Fix ANSOCR TensorRT Release
This commit is contained in:
@@ -323,7 +323,19 @@ private:
|
||||
// unreliable. Don't destroy Engine objects (their destructors
|
||||
// call cudaFree, thread::join, etc. which deadlock or crash).
|
||||
// The OS reclaims all memory, VRAM, and handles at process exit.
|
||||
//
|
||||
// Intentionally leak Engine shared_ptrs: after the explicit dtor
|
||||
// body returns, the compiler still runs implicit member dtors for
|
||||
// m_pools. That would destroy shared_ptr<Engine<T>>, triggering
|
||||
// TRT/CUDA cleanup on a dead context. Detach the shared_ptrs
|
||||
// first so the map destructor only frees empty entries.
|
||||
m_sweeperRunning.store(false);
|
||||
// Leak Engine objects: bump refcount so shared_ptr dtor won't
|
||||
// actually delete them when m_pools is implicitly destroyed.
|
||||
for (auto& [_, entry] : m_pools) {
|
||||
auto* leaked = new std::shared_ptr<Engine<T>>(std::move(entry.engine));
|
||||
(void)leaked; // intentional leak — OS reclaims at exit
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Normal FreeLibrary path: threads are alive, safe to clean up.
|
||||
|
||||
@@ -150,6 +150,18 @@ public:
|
||||
|
||||
private:
|
||||
TRTEngineCache() = default;
|
||||
~TRTEngineCache() {
|
||||
if (g_processExiting().load(std::memory_order_relaxed)) {
|
||||
// ExitProcess path: CUDA context is dead. Leak ICudaEngine and
|
||||
// IRuntime shared_ptrs so their destructors don't call into a
|
||||
// destroyed CUDA driver. The OS reclaims everything at exit.
|
||||
for (auto& [_, entry] : m_cache) {
|
||||
auto* le = new std::shared_ptr<nvinfer1::ICudaEngine>(std::move(entry.engine));
|
||||
auto* lr = new std::shared_ptr<nvinfer1::IRuntime>(std::move(entry.runtime));
|
||||
(void)le; (void)lr; // intentional leak
|
||||
}
|
||||
}
|
||||
}
|
||||
TRTEngineCache(const TRTEngineCache&) = delete;
|
||||
TRTEngineCache& operator=(const TRTEngineCache&) = delete;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user