且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将NSString拆分为子字符串的最有效内存方式

更新时间:2023-11-25 15:41:28

好吧..您不能释放mainHtml,因为它是作为自动释放对象创建的,因此在函数完成后将调用release,并且如果到那时该对象已被释放.

Well.. you can't release mainHtml because it is created as an autorelease object, so release will get called after your function is done and it will crash if the object is already released by then.

您可以尝试创建一个额外的函数来拆分字符串并返回数组,也许有一个自己的自动释放池,您可以在运行该函数后释放该释放池以确保释放了字符串.

You could try to create an extra function that splits the string and returns the array, perhaps with an own autorelease pool that you release after the function is run to make sure the strings are released.