lewes6369 / TensorRT-Yolov3

TensorRT for Yolov3
MIT License
489 stars 165 forks source link

Something is wrong in trtNet::~trtNet() #77

Closed wanxinzzz closed 4 years ago

wanxinzzz commented 4 years ago

when I use

        ~trtNet()
        {
            // Release the stream and the buffers
            cudaStreamSynchronize(mTrtCudaStream);
            cudaStreamDestroy(mTrtCudaStream);
            for(auto& item : mTrtCudaBuffer)
                cudaFree(item);

            mTrtPluginFactory.destroyPlugin();

            if(!mTrtRunTime)
                mTrtRunTime->destroy();
            if(!mTrtContext)
                mTrtContext->destroy();
            if(!mTrtEngine)
                mTrtEngine->destroy();
        };

I found mTrtRunTime->destroy();mTrtContext->destroy();mTrtEngine->destroy();is not used,and i change it to

         if(mTrtContext){
                mTrtContext->destroy();
                std::cout<<"Context destroy"<<std::endl;
            }
            if(mTrtEngine){
                mTrtEngine->destroy();
                std::cout<<"Engine destroy"<<std::endl;
            }               
            if(mTrtRunTime){
                mTrtRunTime->destroy();
                std::cout<<"RunTime destroy"<<std::endl;
            }
            std::cout<<"PluginFactory destroy in"<<std::endl;
            mTrtPluginFactory.destroyPlugin();

It seems to be working good, and the order is important

lewes6369 commented 4 years ago

Thank you very much. It seems my mistakes in the code.I want to check the pointer is not empty but actually used as empty if(!mTrtRunTime) . If remove the operator ! in the condition function, it should be done well.