Luxand FaceSDK v8.3 Developer's Guide

Resource Cleanup Guide

When your application finishes using FaceSDK, all resources should be released.

Cleanup Order

Typically, the cleanup sequence is as follows:

  1. Save tracker memory (if needed) — call FSDK_SaveTrackerMemoryToFile or FSDK_SaveTrackerMemoryToBuffer
  2. Free tracker handles — call FSDK_FreeTracker for each created tracker
  3. Close video cameras — call FSDK_CloseVideoCamera for each open camera

Cleanup Example (C++)

// Proper cleanup sequence with error handling
// Step 1: Save tracker memory if needed
int err = FSDK_SaveTrackerMemoryToFile(tracker, "faces.db");
if (err != FSDKE_OK) {
    // Handle save error - log warning but continue cleanup
    printf("Warning: Failed to save tracker memory (error %d)\n", err);
}

// Step 2: Free all tracker handles
err = FSDK_FreeTracker(tracker);
if (err != FSDKE_OK) {
    printf("Warning: Failed to free tracker (error %d)\n", err);
}

// Step 3: Close all video cameras
err = FSDK_CloseVideoCamera(cameraHandle);
if (err != FSDKE_OK) {
    printf("Warning: Failed to close camera (error %d)\n", err);
}

Cleanup Example (Python)

# Proper cleanup sequence in Python
try:
    # Save tracker memory
    tracker.SaveMemoryToFile("faces.db")
except Exception as e:
    print(f"Warning: Failed to save tracker memory: {e}")

try:
    # Free tracker
    FSDK.FreeTracker(tracker)
except Exception as e:
    print(f"Warning: Failed to free tracker: {e}")

try:
    # Close video camera
    FSDK.CloseVideoCamera(camera_handle)
except Exception as e:
    print(f"Warning: Failed to close camera: {e}")

Best Practices

  • Do not call SDK functions after FSDK_Finalize — once finalized, calling any FaceSDK function results in undefined behavior. You must call FSDK_Initialize again before using the library.
  • Free images in loops — if you process multiple images, free each HImage handle with FSDK_FreeImage after processing to avoid accumulating memory. Do not wait until application exit.
  • Handle partial failures — if one cleanup step fails, continue with the remaining steps. Log the error but do not skip subsequent cleanup calls.
  • Thread safety during cleanup — ensure no other threads are calling FaceSDK functions when you begin the cleanup sequence. Wait for all processing threads to complete before starting cleanup.