-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to release a session properly? #11529
Comments
As long as the ORT object destructors are being called (which call the C OrtApi::Release* methods) the memory is released immediately to the OS. There is no garbage collection inside of Onnxruntime. Can you give more details of what you're looking at? Which OS, and which memory usage metric? |
If you do new, then you are responsible to call delete. |
By the way, the comsumption is not caused by the inference, and the program can run flawlessly for a few days, and not eating any extra memory. Thank you very much. |
bool MessageLite::ParseFrom(const T& input) { |
Should I call ::google::protobuf::ShutdownProtobufLibrary() for each cycle? |
I search kParse and kMergeWithAliasing in onnxruntime code, there is no result found. Is the example code from OnnxRuntime?
I have no experience on this so I cannot answer it. You can have a try. It might introduce other issue. |
Hi tianlei, thank you. "kParse" is argument used in the model loading codes in file "cmake\external\protobuf\src\google\protobuf\message_lite.h". |
I rebuilt onnxruntime with ASAN and got the following leak stack. Wonder if anyone shed some lights on how to release the memory correctly. Indirect leak of 8 byte(s) in 1 object(s) allocated from: |
@ns-wxin Could you use a more recent build? It looks like you're using onnxruntime 1.12.1? Is the leak only 8 bytes? |
Yeah. It's 1.12.1. There's various leaks detected such as the following leaking 536 bytes. Looks like the default constructor of SessionOptions allocated some space but not released. I tried Ort::SessionOptions.release() in my destructor but it didn't seem to get rid of this leak. Direct leak of 536 byte(s) in 1 object(s) allocated from: |
Sorry, the un-necessary release() on session caused most of the leak. Now that is fixed, I'm only seeing the leaking when using extensions. Specifically on CustomDomain related code. `TextMLFingerprintGenerator::TextMLFingerprintGenerator(std::string modelFile, int threadNum)
} std::shared_ptrOrt::Session
}` ==1926430==ERROR: LeakSanitizer: detected memory leaks Direct leak of 56 byte(s) in 1 object(s) allocated from: and Indirect leak of 256 byte(s) in 1 object(s) allocated from: |
I 'm using ORT C++ API to infer several models sequentialy. The consumption of memory is pretty much, so I try to unload some sessones after inference. However the consumption is not fully freed, and no memory leak detected. And I notice that the memory will be freed by the OS after a while (1 hour background alive), I guess, it might be recycled by the mechanism of system garbage collection. So I am wondering it is there some magic API to recycle the garbage, and I would like to know what cause the memory residents, the threads pooling or the weights? Is there a way to tell the OS to do recycle instantly? Thanks.
The text was updated successfully, but these errors were encountered: