Skip to main content

release()

Instance Method | GF225 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 GF225, VTSDeviceFinder

# Initialize sensor
finder = VTSDeviceFinder()
devices = finder.get_devices()
sensor = GF225(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 GF225, VTSDeviceFinder, GFDataType

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

try:
# Use sensor
sensor.calibrate()
data = sensor.collect_sensor_data(GFDataType.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