iOS 10 __abort_with_payload when removing subview

Hello. I'm receiving this crash report (iOS 10 only) for my app:


Crashed: com.apple.main-thread

0 libsystem_kernel.dylib 0x181740d74 __abort_with_payload + 8

1 libsystem_kernel.dylib 0x18173d480 abort_with_payload_wrapper_internal + 100

2 libsystem_kernel.dylib 0x18173d41c abort_with_payload_wrapper_internal + 34

3 libobjc.A.dylib 0x1811abed8 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 112

4 libobjc.A.dylib 0x1811abe30 __objc_error + 42

5 libobjc.A.dylib 0x1811becd4 weak_entry_insert(weak_table_t*, weak_entry_t*) + 318

6 libobjc.A.dylib 0x1811c4664 objc_initWeak + 324

7 UIKit 0x188642e90 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 2068

8 UIKit 0x1885c2830 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1352

9 UIKit 0x1885c25b8 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720

10 UIKit 0x1885c1a64 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 156

11 UIKit 0x1885c18bc -[UIView(Hierarchy) _postMovedFromSuperview:] + 792

12 UIKit 0x1888bee58 __UIViewWasRemovedFromSuperview + 172

13 UIKit 0x1885c0954 -[UIView(Hierarchy) removeFromSuperview] + 512

14 MyApp removes subview from superview


In line 14 i removed custom view from superview, that view has subview which was created from xib file like this:


- (UIView *)createCustomSubview

{

UIViewController* vc = [UIViewController new];

MyCustomView* customView = [customViewNib instantiateWithOwner:vc options:nil][0];

return customView;

}


When debug this issue, debugger says:


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


And it seems that instance of class UIViewController is that vc variable from - (UIView *)createCustomSubview. So it seems like view controller which is file's owner of uiview is deallocated while that view is removing from superview.


I'm, for now, solve this problem by wrap - (UIView *)createCustomSubview content to @autoreleasepool block.


So my question is: is it correct to instantiate nib that way (with temporary view controller as file's owner)?. Do i need to retain file's owner of nib file? What happens when file's owner of xib is deallocated? How can i instantiate multiple different instances of that custom view to avoid this crash?

Do you have solved this problem?? I have the same problem but all iOS 13


CrashReporter Key: ae6f33883d41bb2a03f741910f3ab68708e42789

Hardware Model: iPhone9,4


Date/Time: 2020-06-05T02:10:46Z

Launch Time: 2020-06-05T02:10:45Z

OS Version: iOS 13.3.1 (17D50)

Report Version: 104


Exception Type: EXC_CRASH (SIGABRT)

Exception Codes: 0x00000000 at 0x00000001ae06c930

Crashed Thread: 0


Thread 0 Crashed:

0 libsystem_kernel.dylib 0x1ae06c930 0x1ae049000 + ___abort_with_payload

1 libsystem_kernel.dylib 0x1ae070ec0 0x1ae049000 + _abort_with_payload_wrapper_internal

2 libobjc.A.dylib 0x1adfba244 0x1adf98000 + _objc_fatalv

3 libobjc.A.dylib 0x1adfba1dc 0x1adf98000 + _objc_fatalv

4 libobjc.A.dylib 0x1adfb696c 0x1adf98000 + _weak_clear_no_lock

5 libobjc.A.dylib 0x1adfb86c8 0x1adf98000 + _objc_initWeak

6 UIKitCore 0x1b1ce96f8 0x1b18f9000 + -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]

7 UIKitCore 0x1b2788f54 0x1b18f9000 + -[UIView(Internal) _didMoveFromWindow:toWindow:]

8 UIKitCore 0x1b277d0e0 0x1b18f9000 + ___45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke

9 UIKitCore 0x1b277cfc8 0x1b18f9000 + -[UIView(Hierarchy) _postMovedFromSuperview:]

10 UIKitCore 0x1b277b2b0 0x1b18f9000 + ___UIViewWasRemovedFromSuperview

11 UIKitCore 0x1b277ad90 0x1b18f9000 + -[UIView(Hierarchy) removeFromSuperview]


I remove the view after animation:


[UIView animateWithDuration:0.3f animations:^{

self.loadingView.alpha = 0.0f;

} completion:^(BOOL finished) {

[self.loadingView endLoading];

[self.loadingView removeFromSuperview];

self.loadingView = nil;

}];

iOS 10 __abort_with_payload when removing subview
 
 
Q