Destroy a torch::jit::script::Module in C++ API

Hello there!
I am trying to destroy a torch::jit::script::Module with the C++ API

The Module is loaded in this way:

	torch::jit::script::Module moduleCNN;
	try {
		moduleCNN = torch::jit::load(modelPath, device);
	}
	catch (const c10::Error & e) {
		exit(EXIT_FAILURE);
	}
	moduleCNN.eval();

How can I manage to successfully destroy moduleCNN after I have finished to use it, freeing all the memory associated (not only GPU memory, but also central memory)?

I have tried to make something as:

	torch::jit::script::Module *moduleCNN = new torch::jit::script::Module;
	try {
		(moduleCNN*) = torch::jit::load(modelPath, device);
	}
	catch (const c10::Error & e) {
		exit(EXIT_FAILURE);
	}
	(moduleCNN*).eval();

        ...

        delete moduleCNN;

but it has no effect on the memory occupation.

2 Likes