Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 19, 2025

This PR addresses a crash that occurs when the iOS system attempts to form weak references to view controllers that are in the process of deallocation:

Cannot form weak reference to instance (0x1078ff800) of class UICompatibilityInputViewController. 
It is possible that this object was over-released, or is in the process of deallocation.

While UICompatibilityInputViewController is not directly part of IQKeyboardManager, the library's view controller hierarchy traversal and weak reference management can trigger this crash when UIKit's internal keyboard input system is transitioning or deallocating view controllers.

Root Cause

The crash occurs during view controller lifecycle transitions when:

  1. IQKeyboardManager attempts to traverse the view controller hierarchy
  2. Weak references are formed to view controllers that are being deallocated
  3. The system tries to access properties on over-released objects

Solution

Added comprehensive defensive programming measures to prevent accessing deallocated objects:

Enhanced Weak Reference Handling

  • Added proper weak capture of rootController in Combine publisher sink to prevent retain cycles
  • Added validation that rootController hasn't been deallocated before accessing it
  • Added check to ensure the current rootConfiguration still references the same controller instance

Strengthened Configuration Validation

  • Enhanced all properties in IQRootControllerConfiguration with explicit nil checks
  • Prevents accessing view properties on deallocated view controllers
  • Returns safe defaults when controllers are no longer valid

Improved View Controller Hierarchy Navigation

  • Added safer navigation through parent container view controllers
  • Enhanced cleanup logic to safely restore configurations before clearing them
  • Improved nil-checking when calling iq_parentContainerViewController()

Impact

These changes prevent the "Cannot form weak reference" crash by ensuring that:

  • No operations are attempted on deallocated or over-released objects
  • Weak references are properly validated before use
  • View controller hierarchy traversal is safe during transitions
  • Proper cleanup occurs when view controllers are being deallocated

The fix is minimal and surgical, focusing purely on defensive programming without altering the library's core functionality or public API.

Fixes #2106.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…lityInputViewController crash

Co-authored-by: hackiftekhar <[email protected]>
Copilot AI changed the title [WIP] 6.5.19 still crash Fix UICompatibilityInputViewController weak reference crash with defensive nil-checking Sep 19, 2025
Copilot AI requested a review from hackiftekhar September 19, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6.5.19 still crash

2 participants