How to properly release resources?
Hi,
I am looking for the right way to release resources. I can see in the source code that there's the UnloadNetwork function, but it's not clear for the rest. Would it be possible to have a small code snippet that shows how to release resources?
Thank you very much in advance,
Kind regards,
Hi @mobicham so I can answer your question correctly, which ArmNN resources are you using? IRuntime, Graph, Network, and/or one of the parsers?
Our Create() methods return things in smart pointers, destroying the smart pointer will call the correct destructor.
IRuntime::UnloadNetwork() is a special case for if you want to free up resources in the IRuntime without actually destroying the runtime. You don't need to call it if you are going to destroy the entire IRuntime.
I'm sorry that we don't have simple code snippet demonstrating these things in practice. I hope that in a future release we can include some simple examples. In the meantime in test/InferenceModel.hpp, lines 189-228 you can see the construction of the IRuntime, creating a Network, calling Optimise on that network, and calling LoadNetwork to load the OptimizedNetwork into the Runtime.
All of the things which need destruction and freeing are stored as smart pointers, and the smart pointers are freed implicitly by the destructor of InferenceModel.
Hope that helps, Matthew
Hi @MatthewARM, thank you again for your fast feedback.
I am pretty much following the TF mnist example, so the resources I am using are: ITfParserPtr, INetworkPtr, IRuntime, IOptimizedNetworkPtr. I checked tests/InferenceModel.hpp but I couldn't find the lines you mentioned unfortunately https://github.com/ARM-software/armnn/blob/master/tests/InferenceModel.hpp So if I destroy the runtime, all the resources related to the model are released ? Kind regards
Hi @mobicham,
Destroying the runtime will release all the allocated resources. All the types you mentioned are actually smart pointer, so all resources will be released when the pointer is destroyed.
I hope this helps, Regards Matteo
Thanks a lot @MatteoArm ! I am closing this issue. Kind regards, Hicham