AliSoftware / OHAttributedLabel

UILabel that supports NSAttributedString

Home Page:https://github.com/AliSoftware/OHAttributedLabel/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[OHAttributedLabel drawTextInRect:] crash

nguyentanhoangvu opened this issue · comments

#82
This is another problem of drawTextInRect method.
This issue is frequency crash, so it is difficult to reproduce crashing, so I cannot get more detail to investigate.
Please help me!
Crash log is as below:

Thread 0 Crashed:
1 libobjc.A.dylib _objc_msgSend + 16
2 DemoApplication -OHAttributedLabel drawTextInRect:
3 UIKit -[UILabel drawRect:] + 59
4 UIKit -[UIView(CALayerDelegate) drawLayer:inContext:] + 265
5 QuartzCore -[CALayer drawInContext:] + 93
6 QuartzCore __ZL16backing_callbackP9CGContextPv + 39
7 QuartzCore _CABackingStoreUpdate + 1233
8 QuartzCore -[CALayer _display] + 731
9 QuartzCore -[CALayer display] + 141
10 QuartzCore _CALayerDisplayIfNeeded + 185
11 QuartzCore __ZN2CA7Context18commit_transactionEPNS_11TransactionE + 221
12 QuartzCore __ZN2CA11Transaction6commitEv + 191
13 QuartzCore __ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 57
14 CoreFoundation _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 17
15 CoreFoundation ___CFRunLoopDoObservers + 413
16 CoreFoundation ___CFRunLoopRun + 855
17 CoreFoundation _CFRunLoopRunSpecific + 231
18 CoreFoundation _CFRunLoopRunInMode + 59
19 GraphicsServices _GSEventRunModal + 115
20 GraphicsServices _GSEventRun + 63
21 UIKit -[UIApplication _run] + 405
22 UIKit _UIApplicationMain + 671
23 Cablevision main (main.m:13)

It seems to be a memory managment problem in your usage of OHAttrbutedLabel.
Make sure that you have a strong reference (and not a weak reference) to your OHAttributedLabel instance, and more importantly (as it seems to be revealed by your crashlog) that you did not keep any reference to an OHAttributedLabel instance even after it has been deallocated.

In your case, it seems that you have an observer on some property that triggers an action to your OHAttributedLabel, but that OHAttributedLabel does not exists anymore (has been deallocated in the meantime), but you forgot to remove your observer. Removing the observer when the label is deallocated will then solve the problem (which would not be related to OHAttributedLabel by itself but is a memory mgmt issue in your code)

Migrating your project to ARC will probably be another solution to solve your problem, because the instance will be correctly deallocated and weak references to it will be set to nil (thanks to Zeroing-Weak References)

Thanks for your comment.
My project is using ARC.
I use 7 OHAttributedLabel instances. Once of them, I used retain reference (I have just changed retain to strong reference) and I sure that I use strong reference for other.
I don't have any observer on any property to triggers an action to OHAttributedLabel.
Maybe I am having about memory management problem. I will investigate.
Thanks again.