且构网

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

YAJL内存泄漏问题数组

更新时间:2022-06-27 00:09:15

嗯,看起来很简单. 首先,将JSONData定义为"retain",而不是"assign",然后在后续运行中调用TestMethod时,由于不使用setter,而是直接访问实例变量,因此泄漏了前一个. 如果您不需要在其他任何地方使用JSONData,但是只需使用此方法,只需将其定义为局部变量即可,并且无需执行任何特殊操作-它会自动发布.其次-同样的事情发生在testArray上.同样,如果您不需要在其他地方使用它,则将其定义为局部变量,如果需要,则使用setter.

Well, it looks simple. First, you defined your JSONData as 'retain' instead of 'assign', and then upon calling the TestMethod in subsequent runs, you leak the prior one, as you are not using the setter, but rather accessing the instance variable directly. If you don't need the JSONData in any other place, but this method, just define it as a local variable, and don't do anything special - it's autoreleased. And second - the same thing happens to the testArray. Again, if you don't need it in other places, then define as local variable, and if you do, then use the setter.

更新: 现在您有一个类似的问题,只是这次是deviceListArray. 首先,像这样初始化它:

Update: Now you have a similar problem, just with deviceListArray this time. First, initialize it like this:

self.deviceListArray=[NSMutableArray array];

然后,每次您要分配时,都使用此:

then, every time you want to assign, use this:

self.deviceListArray = newObject;

self.deviceListArray = newObject;

在dealloc中执行

in the dealloc do

[deviceListArray版本];

[deviceListArray release];