I have a question about ARC nad NSMutableArray.
Here’s the case:
I have a ListView with a NSMUtableArray (arr1) that contains all the elements of the listview. A separate thread, which runs in native code, makes callbacks into objective-c ListView. The native code creates a new NSMutableArray (arr2), fills it with elements of my custom class (each element has a name, id, icon etc), then passes it onto the ListView.
In the ListView, first I clear the array with [arr1 removeAllObjects], then I add each element from arr2 to arr1 with [arr1 addObject: ..].
NOTES:
*All the code, both native and objective-c, is compiled as Objective-C++ code.
*The native code part that allocs and init’s arr2 (and all its elements) and calls the ListView stuff is all under @autoreleasepool directive
My questions;
-
Is there any memory leaks from native code?
-
Is there any memory leaks from ListView code? Will the old elements I release with
[arr1 removeAllObjects]cause memory leaks? -
Does @autoreleasepool provide the same functionality as ARC, meaning I wont have to explicitly release the objects?
1) There shouldn’t be, but sometimes there are small leaks (I’ve seen some with the keychain, and some audio libraries). It isn’t your problem for dealing with and in most cases would be impossible to resolve.
2)
removeAllObjectsdoes send release to all the objects in the array. You can see this by putting a break point in the dealloc method.3) yes ARC @autoreleasepool works the same
The situation you’ve described above looks safe to me.