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