Workarounds for memory leak issues caused by using Handyjson

Source: Internet
Author: User

In mobile development, dealing with the server is inevitable, the interface data from the server will eventually be parsed into a model, now the more common data transmission format is the JSON format, the JSON format can be resolved using the native parsing method, you can use the third-party, Our project is using Ali Open source, a swift-written parsing framework--handyjson.

In the process of using instruments's leak checks tool to detect a memory leak, this framework is found to cause a lot of memory leaks, 1-1:

This image is captured when the app enters the home page and the data is loaded, and you can see that Handyjson has resulted in a total of 28 memory leaks, and if the entire app is run again, the number of memory leaks is estimated to be many.

Found a reason on Handyjson's GitHub Click to go, is unsafemutablerawpointer not released caused, the workaround is as follows:

The class name (measuable) and method name (_getbridgedpropertylist) of the memory leak are shown in the leak checks tool, and we find this class and method in Handyjson, It is good to release the unsafemutablerawpointer inside, add the code in the red box in the method 1-2:

After adding the code, we re-examined the memory leak, and found 1-3:

As well as entering the home page and loading the data, we found that the memory leak caused by Handyjson has been lost.

Workarounds for memory leak issues caused by using Handyjson

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.