Find leaked files, sockets, and process resources

Investigate resource leaks in your iOS app by checking open file descriptors, process limits, and remaining capacity.

The iOS file-descriptor suite helps diagnose leaked files, sockets, pipes, and other process resources. It is included in the aggregate Ansight product and can also be installed as AnsightToolsFileDescriptorDiagnostics.

Register the Suite

import AnsightCore
import AnsightToolsFileDescriptorDiagnostics

let diagnosticOptions = AnsightFileDescriptorDiagnosticsOptions(
    includeTargets: false
)

try AnsightRuntime.shared.registerFileDescriptorDiagnosticsTools(
    options: diagnosticOptions
)

Set includeTargets to false to suppress resolved file paths and socket metadata. The options also support a custom maximum scanned descriptor range. If that range is below the process descriptor range, the count tool fails rather than returning a misleading undercount.

Tool Reference

ToolTool idPolicyResult
List Open Descriptorsfile_descriptors.list_openReadFilterable descriptor records with kind, flags, position, inode, and optional target.
Count Open Descriptorsfile_descriptors.count_openReadOnly { "count": number }; it does not resolve targets or collect descriptor details.
Inspect Descriptorfile_descriptors.inspectReadOne descriptor record by non-negative descriptor number.
Get Descriptor Usagefile_descriptors.get_usageReadOpen count, process limits, remaining capacity, and utilization.

file_descriptors.list_open accepts:

  • kind: optional resource-kind filter
  • targetContains: optional case-insensitive target substring
  • maxEntries: maximum records to return after filtering

Snapshot results indicate whether collection was complete, the scanned descriptor limit, and the capture time.

Security

All four tools use .read, but listing and inspection can disclose file paths and socket metadata. Prefer count and usage for routine leak detection, disable targets when paths are unnecessary, and keep the suite limited to controlled development or QA builds.