gpt4 book ai didi

objective-c - 我应该释放 cStringUsingEncoding 返回的字符串吗?

转载 作者:行者123 更新时间:2023-12-04 18:19:18 31 4
gpt4 key购买 nike

如果我调用 [NSString cStringUsingEncoding:] , 我应该 free()一旦我完成使用它?

最佳答案

不,文档说得很清楚:

The returned C string is guaranteed to be valid only until either the receiver is freed, or until the current autorelease pool is emptied, whichever occurs first. You should copy the C string or use getCString:maxLength:encoding: if it needs to store the C string beyond this time.

关于objective-c - 我应该释放 cStringUsingEncoding 返回的字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11013421/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com