Memory leak when textInRange called

Hi,

In my app, I have a custom text view so I've implemented the UITextInput protocol to help me gather text from the keyboard.

I'm getting a strange memory leak when the method textInRange is called:

- (NSString *)textInRange:(UITextRange *)range

{

    if (self.keyboardInputAccessoryMenuView)

    {

        IndexedRange *r = (IndexedRange *)range;

        NSString *textString = self.labelView.labelTextView.text.string;

        

        if ([self rangeExists: r.range inString:textString])

        {

            return ([textString substringWithRange:r.range]);

        }

        else

        {

            return nil;

        }

    }

    else

    {

        return nil;

    }

}

"text" is an NSMutableAttributedString. The error exists at the following line:

return ([textString substringWithRange:r.range]);

This is the crash log I'm getting:

Crashed: com.apple.main-thread

 0  libsystem_platform.dylib       0x1e086f754 _platform_memmove + 340

1  CoreFoundation                 0x1942671cc __CFStringCreateImmutableFunnel3 + 2588

2  CoreFoundation                 0x19426b8a4 CFStringCreateWithSubstring + 524

3  CoreFoundation                 0x1941b24e0 -[__NSCFString substringWithRange:] + 164

4  Label Maker            0x102166604 -[LabelWindowView textInRange:] + 968 (LabelWindowView.m:968)

5  UIKit                          0x1e0b4bdb8 -[UITextInputUIResponderAccessibility accessibilityValue] + 172

6  UIAccessibility                0x1a85f7c40 -[NSObject(AXPrivCategory) _accessibilityPotentiallyAttributedValueForNonAttributedSelector:attributedSelector:] + 284

7  UIAccessibility                0x1a85f7ebc -[NSObject(AXPrivCategory) _accessibilityAXAttributedValue] + 48

8  UIAccessibility                0x1a85fdd10 -[NSObject(AXPrivCategory) _iosAccessibilityAttributeValue:] + 5516

9  UIAccessibility                0x1a862ebf8 _accessibilityAttributesForObject + 412

10 UIAccessibility                0x1a862e384 -[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotDescendantsWithAttributes:maxDepth:maxChildren:maxArrayCount:honorsModalViews:] + 888

11 UIAccessibility                0x1a862ff8c -[NSObject(UIAccessibilityAutomation) _accessibilityUserTestingSnapshotWithOptions:] + 1112

12 UIAccessibility                0x1a85fb8b0 -[NSObject(AXPrivCategory) _iosAccessibilityAttributeValue:forParameter:] + 11464

13 UIKit                          0x1e0abbae0 -[UIApplicationAccessibility _iosAccessibilityAttributeValue:forParameter:] + 308

14 UIAccessibility                0x1a85d6648 _copyParameterizedAttributeValueCallback + 408

15 AXRuntime                      0x1b3c50dd8 ___AXXMIGCopyParameterizedAttributeValue_block_invoke + 64

16 AXRuntime                      0x1b3c505e4 _handleNonMainThreadCallback + 68

17 AXRuntime                      0x1b3c50c60 _AXXMIGCopyParameterizedAttributeValue + 388

18 AXRuntime                      0x1b3c9f074 _XCopyParameterizedAttributeValue + 392

19 AXRuntime                      0x1b3c60200 mshMIGPerform + 272

20 CoreFoundation                 0x194245fe8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 60

21 CoreFoundation                 0x194245378 __CFRunLoopDoSource1 + 596

22 CoreFoundation                 0x19423f08c __CFRunLoopRun + 2360

23 CoreFoundation                 0x19423e21c CFRunLoopRunSpecific + 600

24 GraphicsServices               0x1abe0a784 GSEventRunModal + 164

25 UIKitCore                      0x196c7eee8 -[UIApplication _run] + 1072

26 UIKitCore                      0x196c8475c UIApplicationMain + 168

27 Label Maker            0x102140100 main + 15 (main.m:15)

28 libdyld.dylib                  0x193efe6b0 start + 4

This code in this function works most of the time, but occasionally I get this bug out of nowhere and can't recreate it.

Can anyone offer any insight on this?

What is the actual error that you are getting? This doesn't seem like a memory leak.

I am getting:

Crashed: com.apple.main-thread  EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x000000027fffffea

If that's what you mean.

Well, that’s definitely not a memory leak (-:

Can you post an Apple crash report for this. Use the text attachment feature (click the paperclip icon and then choose Add File) to avoid clogging up the timeline.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Memory leak when textInRange called
 
 
Q