Skip to main content

release()

Instance Method | VTSensor Sensor Class

📖 Method Description​

Release resources occupied by the sensor instance, including closing device connections, freeing memory, etc. This method should be called after using the sensor to ensure resources are properly released.


📝 Syntax​

sensor.release()

🔧 Parameters​

No parameters


📤 Return Type​

No return value


💡 Example Code​

Basic Usage​

from pyvitaisdk import VTSensor, VTSDeviceFinder

# Initialize sensor
finder = VTSDeviceFinder()
devices = finder.get_devices()
sensor = VTSensor(devices[0])

# Use sensor...
sensor.calibrate()
# ... perform data collection and other operations ...

# Release resources
sensor.release()
print("Sensor resources released")

Using try-finally to Ensure Resource Release​

from pyvitaisdk import VTSensor, VTSDeviceFinder, VTSDataType

finder = VTSDeviceFinder()
devices = finder.get_devices()
sensor = VTSensor(devices[0])

try:
# Use sensor
sensor.calibrate()
data = sensor.collect_sensor_data(VTSDataType.WARPED_IMG)
# ... process data ...

finally:
# Ensure resources are released
sensor.release()
print("Resources safely released")

⚠️ Notes​

Important Reminder
  • Must call the release() method after using the sensor
  • Not releasing resources may prevent the device from being opened again
  • May cause memory leaks and resource occupation
Best Practices

Recommended approaches (in order of priority):

  1. Exception Handling - Use try-finally blocks to ensure resources are released even in case of exceptions
  2. Manual Calling - Remember to call at the appropriate time
Multi-sensor Scenarios

When using multiple sensors simultaneously:

  • Each sensor instance needs to be released separately
  • Recommend releasing in reverse order of creation
Behavior After Release
  • A released sensor instance cannot be used again
  • Need to recreate the instance to use the sensor again