Hello, I encountered a memory management issue while developing VPN functionality and would like to seek your advice. The specific phenomenon is as follows: Problem description: After multiple calls to the 'createTCPConnectToEndpoint' and 'create UDPSessionToEndpoint' interfaces to create connection objects, the application memory continues to grow. Even if the cancel interface is immediately called to actively release the object, the memory does not fall back. 3. Confirm that there is no other code referencing these objects, but the system does not seem to automatically reclaim memory. Attempted measures:
- Immediately call the cancel method after creating the object, and the memory is not reduced
- Use tools such as Profiler to monitor memory and confirm that objects have not been released.
doubt: Is this phenomenon normal? Is there a known memory management mechanism (such as cache pooling) that causes delayed release? 2. Are there any other interfaces or methods (such as release, dispose) that need to be explicitly called? Supplementary Information: Development environment: [iOS 16, 14pm] Reproduction steps: After continuously creating connection objects, the memory grows without falling back. Could you please help confirm if there are any abnormalities and the correct memory release posture. Thank you for your support!
There are two parts to this:
-
How do you use these APIs correctly?
-
Should you be using these APIs at all?
I’m gonna start with the second one.
The APIs you mentioned are known as in-provide networking APIs. These APIs are deprecated in favour of Network framework. My general advice is that you not use these APIs for new code and, if you have existing code, plan to move to Network framework sooner rather than later.
For general advice on our networking APIs, see TN3151 Choosing the right networking API.
As to why you’re having memory management problems, it’s hard to say without more info. My advice is that you start by using Xcode’s memory graph feature to determine what’s holding the objects in memory.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"