How could I create the following array without having memory leaks:
It should be an array with arrays inside
arr = [[NSMutableArray alloc] initWithObjects:
[[NSMutableArray alloc] init],
[[NSMutableArray alloc] init],
[[NSMutableArray alloc] init],
[[NSMutableArray alloc] init],
[[NSMutableArray alloc] init],
[[NSMutableArray alloc] init],
[[NSMutableArray alloc] init], nil];
Use
[NSMutableArray array]instead, which creates an autoreleased object that you don’t have to worry about:Note that you must retain / release
arrif you want to hold onto it.If what you really want is simply arrays of arrays, I have a class called
RJGridwhich will do this for you, and is faster than multipleNSMutableArrays(linked lists are slow for lookups).You can download the class here, in my dropbox. It uses ARC, but is simple enough to convert to a reference counted environment, if you want me to do that.