Excessive memory usage by UITextView on iOS 7

Number:rdar://15799494 Date Originated:11-Jan-2014 02:45 PM
Status:Duplicate of 15487867 (Open) Resolved:
Product:iOS SDK Product Version:7.0.4 & 7.1b3
Classification:Performance Reproducible:
I'm seeing an excessive memory usage (in All Anonymous VM > VM: CoreAnimation category) of UITextView under iOS 7.0.4 and 7.1beta3. For example when the 774 KB text file (http://www.gutenberg.org/cache/epub/98/pg98.txt) is loaded into the text view and the app is run only 6 MBs are allocated at the beginning. When scrolling, memory consumption keeps growing. When the end of the document is reached, around 800 MBs (see https://www.dropbox.com/s/d2u540r0b7rupkp/bug_report_text_view_memory.png) are allocated by VM:CoreAnimation.
On the iPhone 4 the text starts disappearing (the background is still visible) when about 70% progress is reached and then the application crashes. iOS doesn't send the low memory notification in this situation.

I know that loading such a large string into UITextView is uncommon, however it's useful as an example of this bug.

Steps to Reproduce:
1. Create a Single View Application, add a text view and load the text from the large file, e.g. the one I linked above OR use the project I attached to this bug report
2. Profile the app with Allocations template
3. Check "All Heap & Anonymous VM" in "Allocation Type"
4. Scroll the text view and observe the growth of memory consumption

Expected Results:
Memory usage shouldn't grow so rapidly. iOS should send the low memory notification. The app shouldn't crash. When the same file: http://www.gutenberg.org/cache/epub/98/pg98.txt is opened in Safari everything works fine, so the performance of the native view is worse than the web view.

Actual Results:
Memory consumption grows continuously while scrolling, causing the app to crash.

iOS 7.0.4 & iOS 7.1b3


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!