In the app's content page (Detail page), Rich text display has always been a problem to deal with, and usually in the back-end Rich text editing, HTML application is more common, so actually need to deal with the HTML Rich text display problem, the following three ways is certainly not the best way to display HTML Rich text, Just a relatively simple solution, the conversion requirements for the front and back end are small and can be quickly integrated.
The following 3 ways to test the memory of the comparison, after all, the details page is relatively large, and open the high frequency of the page, so memory consumption is a must consider the problem.
Basic Environment:
- Objective-c
- Xcode 6.4
- Deployment Target IOS 8.0
- Dtcoretext version: 1.6.16
Description
- Dtcoretext: Third-party Rich text display component, support HTML conversion to nsattributedstring;
- Wkwebview:ios's WebKit framework for browser components, starting with IOS 8.0 support;
- Uiwebview:ios's Uikit framework for browser components, starting with IOS 2.0 support;
Test method:
- Use 3 components to display the contents of a Web page (for example: http://news.dayoo.com/guangzhou/201512/11/139995_45489706.htm);
- After loading the page, empty the content, load the content again, repeat 3 times;
- Compare the memory consumption of 3 components;
Memory Debug Tool: Instruments Test Result: Dtcoretext wkwebview UIWebView
Memory consumption at run time: Dtcoretext < Wkwebview < UIWebView
Memory consumption at end of run: Wkwebview < Dtcoretext < UIWebView
UIWebView has been criticized by the memory of the problem is still unresolved, if you need to open the HTML page more complex (especially with a lot of JS) or use it cautiously, the new wkwebview really better than UIWebView in memory management, if the app can abandon iOS 7 Or the following version, worth using, at least in memory footprint has been with the original nsattributedstring gap is not so big, in iOS device memory and performance higher, the gap will be smaller, and pure HTML page flexibility will be higher.
Before using UIWebView, tried various methods of releasing memory, including setting Nsurlcache, emptying Nsurlcache and other methods, but the actual role is not very much, so in the test did not use these methods, just use the [_webcontent Loadhtmlstring:nil Baseurl:nil]; to clear the content;
Lnmp_ios Small set of TUMG
Links: Https://www.jianshu.com/p/9f5ac4d47ef4
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
IOS HTML Rich Text rendering method: Dtcoretext, Wkwebview, UIWebView memory footprint Comparison