Releases controller handle and frees associated resources.
Takes controller (controller handle from inpCreateController, positive integer).
Returns nothing.
Input
Parameters & Returns
Parameters
controllerInt
Returns
Void
Quick Summary
Releases controller handle and frees associated resources.
Takes controller (controller handle from inpCreateController, positive integer).
Returns nothing.
Technical Exegesis...
Releases controller handle and frees associated resources. Takes controller (controller handle from inpCreateController, positive integer). Returns nothing. Cleans up controller state memory and invalidates handle, call when controller no longer needed.
Releases controller handle and frees associated resources. Takes controller (controller handle from inpCreateController, positive integer). Returns nothing. Cleans up controller state memory and invalidates handle, call when controller no longer needed.
Resource cleanup: deallocates controller state tracking memory (button history, stick values, ~100 bytes), invalidates controller handle (handle becomes unusable after free), stops controller input polling (no more updates for this handle), releases system resources (XInput/DirectInput cleanup if applicable).
Use cases: (1) Game shutdown (free all controllers before exit), (2) Controller removal (free handle when player leaves multiplayer session), (3) Resource management (free unused controllers to reclaim memory), (4) Error cleanup (free handle if controller initialization failed partway), (5) Dynamic controller management (free and recreate controllers as needed).
Common patterns: cleanup = inpFreeController(controller%): controller%=0 (free and invalidate handle); game exit = For i=0 To 3: If controllers%(i)>0 Then inpFreeController(controllers%(i)): Next; conditional free = If controller%>0 Then inpFreeController(controller%) (check valid handle first).
When to call: during game shutdown (free all created controllers before exit), when controller no longer needed (player quit, controller disabled), before recreating controller (free old handle before creating new), on cleanup after error (if initialization partially succeeded).
Handle invalidation: after inpFreeController, handle becomes invalid (do not use with other inp functions), further calls with freed handle may crash or error (behavior undefined), set handle variable to 0 or -1 after free (prevent accidental reuse: inpFreeController(controller%): controller%=0).
Performance: fast cleanup (~0.01-0.1ms, one-time cost), small memory freed (~100 bytes per controller), no ongoing performance impact (one-time operation).
Safety: safe to call with valid handle (always succeeds for valid handles), calling with invalid handle may error (check handle > 0 before calling), calling twice with same handle undefined (may crash or error, avoid double-free), no effect on other controllers (only frees specified handle).
Memory leaks: failure to call inpFreeController causes memory leak (small, ~100 bytes per controller), not critical for typical games (leak is small and happens at exit), best practice to free all handles (clean shutdown, especially for long-running applications).
Error handling: may print error if invalid handle (check stderr for messages), silently succeeds if handle already freed (though behavior undefined, avoid), no return value to check (assume success for valid handle).
Related: inpCreateController creates controller handle (allocates resources), inpIsControllerConnected checks connection status (call before freeing if checking), inpUpdateController updates controller state (don't call after free).