I have 2 arrays, 1 in the viewDidLoad method and 1 in the add method (adds the object to the favorites)
NSUserDefaults * myDefault = [NSUserDefaults Standard User Default]; NSArray * prefs = [myDefault arrayForKey: @ "added prefs"]; UserAdded = [[NSMutableArray alloc] initWithArray: prefs]; The device is showing leaks from these prefs NSARR (only one shown above, exactly the same in other food stuff), when I try to issue them an app crash, , I can not leave them in the Dealog method.
Is it possible to assign the NSMutable array directly to the array of my users? Or will this cause a mismatch?
How can this leak be stopped? The documentation is not specified if initWithArray: If the new array is added to the new array (userAdded), then the old one (prefaces) Sends an object in This is needed because the item is being added to the new array. It may be that when the old array (prefus) is removed, counting on the elements present in the user is retained, it gets much lower, the object is also deloquent, and the app crashes. To check this, I asked the contents of the first array for my counting before and after calling the inverter.
NSUserDefaults * myDefault = [NSUserDefaults standard user default]; NSArray * prefs = [myDefault arrayForKey: @ "added prefs"]; NSUInteger i, count = [prefix count]; For (i = 0; i & lt; counts; i ++) {NSObject * obj = [Prefs objectAtIndex: i]; NSLog (@ "Object:% @, retain count:% D.", OBJ, [OBJ maintained number]); } Added user = [[NSMutableArray alloc] initWithArray: prefs]; For (i = 0; i & lt; counts; i ++) {NSObject * obj = [Prefs objectAtIndex: i]; NSLog (@ "Object:% @, retain count:% D.", OBJ, [OBJ maintained number]); } Objects report an increased number of counts, so prefix arrays can be issued without affecting the new array. But running this code still leads to an NSArray leak.
The problem should lie with the prefix array. Since the NSUserDelfaults method arrayForKey: Prefs produces array, even then the words "alloc", "new", or "copy" are not found in the name of this method, the calling method is not the prefs array. Most likely, the prefaces array was added to an autorax pool. To test this idea, I surrounded the above test code with a call to NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init], and [pool drain] took. Running this code does not leak an array.
So I think the prefaces are being added to an autoriz pool which does not get dry. The easiest way to eliminate this leak will be to create an auto-ray pool before creating the prefix array, and after completing the prefaces array, remove that pool.
Comments
Post a Comment