WEBVTT

00:00.080 --> 00:00.920
Welcome back.

00:01.240 --> 00:07.600
The interpreter object from TensorFlow Lite holds the loaded model in memory.

00:07.840 --> 00:16.960
Models can be large and the interpreter uses native resources like C++ memory, not just the JVM.

00:17.120 --> 00:20.880
If you don't close it, you may leak memory.

00:20.960 --> 00:26.640
So for that, we're going to use the function close here.

00:26.800 --> 00:31.080
And inside it we're gonna close the interpreter.

00:31.240 --> 00:37.600
So interpreter dot close and interpreter equals to null.

00:37.640 --> 00:43.080
After closing the interpreter you set the variable to null.

00:43.320 --> 00:45.280
This does two things.

00:45.280 --> 00:45.640
Here.

00:45.640 --> 00:53.960
We are preventing the accidental reuse of a closed interpreter and helps garbage collection.

00:54.000 --> 00:57.840
The object reference is cleared so it can be freed.

00:57.880 --> 01:01.160
We need to close the interpreter to free up resources.

01:01.160 --> 01:07.920
Interpreter is not garbage collected, so it needs to be closed explicitly and preventing accidental

01:07.920 --> 01:11.080
reuse of closed interpreter and helping garbage collection.

01:11.080 --> 01:16.120
By freeing up resources, we assigned the interpreter to null.

01:16.160 --> 01:20.120
Okay, so this is the function how we free up memory.

01:20.120 --> 01:23.080
And this close function is a clean up method.

01:23.080 --> 01:27.680
It shuts down the TensorFlow Lite interpreter safely.

01:27.840 --> 01:30.280
It releases system memory.

01:30.440 --> 01:35.400
It ensures the variable won't point to a dead object.
